[PATCH 0/8] Several related cleanup patches
These patches were all the result of a failed attempt to provide more useful error messages when libvirt is started with an insufficiently setup environment (e.g. $HOME isn't set and/or the XDG_* environment variables aren't set) which currently results in unhelpful log messages (for an example see https://issues.redhat.com/browse/RHEL-105490). The way I was trying to improve the log messages didn't work out the way I'd hoped (long story), but these patches are generally good (or, for the last two, at least are fodder for discussion). You can put them into 3 categories: 1) reducing the scope of some autofree strings / renaming functions 2) consistently use g_getenv/g_setenv 3) stop mocking virGetUserRuntimeDirectory in tests, and instead point the environment at a properly initialiazed test directory tree. (I suppose I could have sent them in separate threads, but they were all in a single branch so sending them together created less "local bureacracy") Laine Stump (8): util: reduce scope/autofree-ify rundir in virDaemonUnixSocketPaths() util: reduce scope of rundir in virPidFileConstructPath() remote: reduce scope of userdir in remoteGetUNIXSocketHelper() util: rename virGetUserDirectory(ByUID) to virGetUserHomeDirectory(ByUID) util: make completely separate functions for WIN32 versions of virGetUser*Directory() consistently use glib g_getenv() instead of libc getenv() tests: point $HOME and $XDG_* into usable fake root directory tests: stop mocking virGetUserRuntimeDirectory() scripts/rpcgen/tests/test_demo.c | 2 +- src/admin/libvirt-admin.c | 2 +- src/hyperv/hyperv_driver.c | 2 +- src/libvirt.c | 2 +- src/libvirt_private.syms | 4 +-- src/network/leaseshelper.c | 14 ++++---- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_interop_config.c | 4 +-- src/remote/remote_sockets.c | 7 ++-- src/rpc/virnetclient.c | 4 +-- src/rpc/virnetlibsshsession.c | 2 +- src/rpc/virnettlsconfig.c | 2 +- src/rpc/virnettlscontext.c | 2 +- src/util/virauth.c | 2 +- src/util/vircommand.c | 2 +- src/util/virdaemon.c | 13 ++------ src/util/virfile.c | 4 +-- src/util/virlease.c | 4 +-- src/util/virlog.c | 6 ++-- src/util/virpidfile.c | 4 +-- src/util/virsystemd.c | 8 ++--- src/util/virutil.c | 55 +++++++++++++++++++++---------- src/util/virutil.h | 4 +-- src/vbox/vbox_XPCOMCGlue.c | 2 +- src/vbox/vbox_common.c | 2 +- src/vbox/vbox_storage.c | 2 +- tests/eventtest.c | 2 +- tests/fdstreamtest.c | 2 +- tests/meson.build | 1 - tests/qemucpumock.c | 2 +- tests/qemuhotplugtest.c | 1 - tests/qemusecuritymock.c | 16 ++++----- tests/securityselinuxhelper.c | 10 +++--- tests/testutils.c | 56 +++++++++++++++++++++++--------- tests/testutils.h | 2 +- tests/testutilsqemu.c | 2 +- tests/vircgroupmock.c | 10 +++--- tests/virfilemock.c | 8 ++--- tests/virhostdevmock.c | 15 --------- tests/virhostdevtest.c | 3 +- tests/virmockstathelpers.c | 2 +- tests/virnetdaemontest.c | 2 +- tests/virnettlshelpers.c | 2 +- tests/virpcimock.c | 2 +- tests/virportallocatormock.c | 4 +-- tests/virscsitest.c | 2 +- tests/virsystemdtest.c | 14 ++++---- tests/virtestmock.c | 6 ++-- tools/virsh.c | 2 +- tools/virt-login-shell-helper.c | 4 +-- tools/vsh.c | 14 ++++---- 51 files changed, 179 insertions(+), 162 deletions(-) delete mode 100644 tests/virhostdevmock.c -- 2.52.0
From: Laine Stump <laine@redhat.com> Signed-off-by: Laine Stump <laine@redhat.com> --- src/util/virdaemon.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/util/virdaemon.c b/src/util/virdaemon.c index 7a288f81e4..cb2c55d1bc 100644 --- a/src/util/virdaemon.c +++ b/src/util/virdaemon.c @@ -216,9 +216,6 @@ virDaemonUnixSocketPaths(const char *sock_prefix, char **rosockfile, char **admsockfile) { - int ret = -1; - char *rundir = NULL; - if (unix_sock_dir) { if (sockfile) *sockfile = g_strdup_printf("%s/%s-sock", unix_sock_dir, sock_prefix); @@ -244,13 +241,12 @@ virDaemonUnixSocketPaths(const char *sock_prefix, RUNSTATEDIR, sock_prefix); } else { mode_t old_umask; - - rundir = virGetUserRuntimeDirectory(); + g_autofree char *rundir = virGetUserRuntimeDirectory(); old_umask = umask(077); if (g_mkdir_with_parents(rundir, 0777) < 0) { umask(old_umask); - goto cleanup; + return -1; } umask(old_umask); @@ -261,10 +257,7 @@ virDaemonUnixSocketPaths(const char *sock_prefix, } } - ret = 0; - cleanup: - VIR_FREE(rundir); - return ret; + return 0; } #else /* WIN32 */ -- 2.52.0
From: Laine Stump <laine@redhat.com> Signed-off-by: Laine Stump <laine@redhat.com> --- src/util/virpidfile.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index f61caca2de..dacaffc929 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -526,8 +526,6 @@ virPidFileConstructPath(bool privileged, const char *progname, char **pidfile) { - g_autofree char *rundir = NULL; - if (privileged) { /* * This is here just to allow calling this function with @@ -540,7 +538,7 @@ virPidFileConstructPath(bool privileged, } *pidfile = g_strdup_printf("%s/%s.pid", runstatedir, progname); } else { - rundir = virGetUserRuntimeDirectory(); + g_autofree char *rundir = virGetUserRuntimeDirectory(); if (g_mkdir_with_parents(rundir, 0700) < 0) { virReportSystemError(errno, -- 2.52.0
From: Laine Stump <laine@redhat.com> Signed-off-by: Laine Stump <laine@redhat.com> --- src/remote/remote_sockets.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/remote/remote_sockets.c b/src/remote/remote_sockets.c index b3f6cd6a42..13b760355b 100644 --- a/src/remote/remote_sockets.c +++ b/src/remote/remote_sockets.c @@ -126,10 +126,9 @@ remoteGetUNIXSocketHelper(remoteDriverTransport transport, unsigned int flags) { char *sockname = NULL; - g_autofree char *userdir = NULL; if (flags & REMOTE_DRIVER_OPEN_USER) { - userdir = virGetUserRuntimeDirectory(); + g_autofree char *userdir = virGetUserRuntimeDirectory(); sockname = g_strdup_printf("%s/%s-sock", userdir, sock_prefix); } else { -- 2.52.0
From: Laine Stump <laine@redhat.com> All the other wrapper functions for glib g_get_user_*_dir() have the type of directory (the "*" in that wildcarded name) in the libvirt function name. These functions, on the other hand, call g_get_home_dir(), but the libvirt API is called virGetUserDirectory*(). Let's make it *a bit* closer to consistent (at least the libvirt API names will be consistent with each other, even if glib isn't). Signed-off-by: Laine Stump <laine@redhat.com> --- src/libvirt_private.syms | 4 ++-- src/qemu/qemu_interop_config.c | 2 +- src/rpc/virnetclient.c | 4 ++-- src/rpc/virnettlsconfig.c | 2 +- src/util/virutil.c | 10 +++++----- src/util/virutil.h | 4 ++-- src/vbox/vbox_storage.c | 2 +- tools/virt-login-shell-helper.c | 2 +- tools/vsh.c | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b200037189..a2636652ef 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3723,8 +3723,8 @@ virGetSystemPageSize; virGetSystemPageSizeKB; virGetUserCacheDirectory; virGetUserConfigDirectory; -virGetUserDirectory; -virGetUserDirectoryByUID; +virGetUserHomeDirectory; +virGetUserHomeDirectoryByUID; virGetUserID; virGetUserName; virGetUserRuntimeDirectory; diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c index 08fb68c901..2280b8a2df 100644 --- a/src/qemu/qemu_interop_config.c +++ b/src/qemu/qemu_interop_config.c @@ -105,7 +105,7 @@ qemuInteropFetchConfigs(const char *name, xdgConfig = g_strdup(getenv("XDG_CONFIG_HOME")); if (!xdgConfig) { - g_autofree char *home = virGetUserDirectory(); + g_autofree char *home = virGetUserHomeDirectory(); xdgConfig = g_strdup_printf("%s/.config", home); } diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index ee729d5e62..3ad4655e6e 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -539,7 +539,7 @@ virNetClient *virNetClientNewLibSSH2(const char *host, if (privkeyPath) { privkey = g_strdup(privkeyPath); } else { - homedir = virGetUserDirectory(); + homedir = virGetUserHomeDirectory(); if (virNetClientFindDefaultSshKey(homedir, &privkey) < 0) return NULL; } @@ -604,7 +604,7 @@ virNetClient *virNetClientNewLibssh(const char *host, if (privkeyPath) { privkey = g_strdup(privkeyPath); } else { - homedir = virGetUserDirectory(); + homedir = virGetUserHomeDirectory(); if (virNetClientFindDefaultSshKey(homedir, &privkey) < 0) return NULL; } diff --git a/src/rpc/virnettlsconfig.c b/src/rpc/virnettlsconfig.c index eec20cf6b7..6ad7a02779 100644 --- a/src/rpc/virnettlsconfig.c +++ b/src/rpc/virnettlsconfig.c @@ -36,7 +36,7 @@ VIR_LOG_INIT("rpc.nettlsconfig"); char *virNetTLSConfigUserPKIBaseDir(void) { - g_autofree char *userdir = virGetUserDirectory(); + g_autofree char *userdir = virGetUserHomeDirectory(); return g_strdup_printf("%s/.pki/libvirt", userdir); } diff --git a/src/util/virutil.c b/src/util/virutil.c index fb64237692..3c0d04c3d7 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -589,7 +589,7 @@ virGetHostnameQuiet(void) char * -virGetUserDirectory(void) +virGetUserHomeDirectory(void) { return g_strdup(g_get_home_dir()); } @@ -753,7 +753,7 @@ static char *virGetGroupEnt(gid_t gid) char * -virGetUserDirectoryByUID(uid_t uid) +virGetUserHomeDirectoryByUID(uid_t uid) { char *ret; virGetUserEnt(uid, NULL, NULL, &ret, NULL, false); @@ -1091,7 +1091,7 @@ virDoesGroupExist(const char *name G_GNUC_UNUSED) # ifdef WIN32 char * -virGetUserDirectoryByUID(uid_t uid G_GNUC_UNUSED) +virGetUserHomeDirectoryByUID(uid_t uid G_GNUC_UNUSED) { /* Since Windows lacks setuid binaries, and since we already fake * geteuid(), we can safely assume that this is only called when @@ -1111,10 +1111,10 @@ virGetUserShell(uid_t uid G_GNUC_UNUSED) # else /* !WITH_GETPWUID_R && !WIN32 */ char * -virGetUserDirectoryByUID(uid_t uid G_GNUC_UNUSED) +virGetUserHomeDirectoryByUID(uid_t uid G_GNUC_UNUSED) { virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("virGetUserDirectory is not available")); + "%s", _("virGetUserHomeDirectory is not available")); return NULL; } diff --git a/src/util/virutil.h b/src/util/virutil.h index 7e1705e7ce..2accb5777d 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -95,8 +95,8 @@ static inline int pthread_sigmask(int how, char *virGetHostname(void) ATTRIBUTE_MOCKABLE; char *virGetHostnameQuiet(void); -char *virGetUserDirectory(void); -char *virGetUserDirectoryByUID(uid_t uid); +char *virGetUserHomeDirectory(void); +char *virGetUserHomeDirectoryByUID(uid_t uid); char *virGetUserConfigDirectory(void); char *virGetUserCacheDirectory(void); char *virGetUserRuntimeDirectory(void) ATTRIBUTE_MOCKABLE; diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c index 56be618fb8..72c67d2143 100644 --- a/src/vbox/vbox_storage.c +++ b/src/vbox/vbox_storage.c @@ -445,7 +445,7 @@ vboxStorageVolCreateXML(virStoragePoolPtr pool, /* If target.path isn't given, use default path ~/.VirtualBox/image_name */ if (!def->target.path) { - homedir = virGetUserDirectory(); + homedir = virGetUserHomeDirectory(); def->target.path = g_strdup_printf("%s/.VirtualBox/%s", homedir, def->name); } VBOX_UTF8_TO_UTF16(def->target.path, &hddNameUtf16); diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helper.c index cb59b5dec0..a1c68a1afa 100644 --- a/tools/virt-login-shell-helper.c +++ b/tools/virt-login-shell-helper.c @@ -253,7 +253,7 @@ main(int argc, char **argv) if (!name) goto cleanup; - homedir = virGetUserDirectoryByUID(uid); + homedir = virGetUserHomeDirectoryByUID(uid); if (!homedir) goto cleanup; diff --git a/tools/vsh.c b/tools/vsh.c index 69d3930e43..18914cc818 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3333,7 +3333,7 @@ cmdCd(vshControl *ctl, const vshCmd *cmd) g_autofree char *dir_malloced = NULL; if (vshCommandOptStringQuiet(ctl, cmd, "dir", &dir) <= 0) - dir = dir_malloced = virGetUserDirectory(); + dir = dir_malloced = virGetUserHomeDirectory(); if (!dir) dir = "/"; -- 2.52.0
On 2/24/26 09:22, Laine Stump via Devel wrote:
From: Laine Stump <laine@redhat.com>
All the other wrapper functions for glib g_get_user_*_dir() have the type of directory (the "*" in that wildcarded name) in the libvirt function name. These functions, on the other hand, call g_get_home_dir(), but the libvirt API is called virGetUserDirectory*(). Let's make it *a bit* closer to consistent (at least the libvirt API names will be consistent with each other, even if glib isn't).
Signed-off-by: Laine Stump <laine@redhat.com> --- src/libvirt_private.syms | 4 ++-- src/qemu/qemu_interop_config.c | 2 +- src/rpc/virnetclient.c | 4 ++-- src/rpc/virnettlsconfig.c | 2 +- src/util/virutil.c | 10 +++++----- src/util/virutil.h | 4 ++-- src/vbox/vbox_storage.c | 2 +- tools/virt-login-shell-helper.c | 2 +- tools/vsh.c | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/util/virutil.c b/src/util/virutil.c index fb64237692..3c0d04c3d7 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -589,7 +589,7 @@ virGetHostnameQuiet(void)
char * -virGetUserDirectory(void) +virGetUserHomeDirectory(void) { return g_strdup(g_get_home_dir()); } @@ -753,7 +753,7 @@ static char *virGetGroupEnt(gid_t gid)
char * -virGetUserDirectoryByUID(uid_t uid) +virGetUserHomeDirectoryByUID(uid_t uid) { char *ret; virGetUserEnt(uid, NULL, NULL, &ret, NULL, false); @@ -1091,7 +1091,7 @@ virDoesGroupExist(const char *name G_GNUC_UNUSED)
# ifdef WIN32 char * -virGetUserDirectoryByUID(uid_t uid G_GNUC_UNUSED) +virGetUserHomeDirectoryByUID(uid_t uid G_GNUC_UNUSED) { /* Since Windows lacks setuid binaries, and since we already fake * geteuid(), we can safely assume that this is only called when @@ -1111,10 +1111,10 @@ virGetUserShell(uid_t uid G_GNUC_UNUSED)
# else /* !WITH_GETPWUID_R && !WIN32 */ char * -virGetUserDirectoryByUID(uid_t uid G_GNUC_UNUSED) +virGetUserHomeDirectoryByUID(uid_t uid G_GNUC_UNUSED) { virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("virGetUserDirectory is not available")); + "%s", _("virGetUserHomeDirectory is not available"));
I think this should be either full function name, or an error message not containing the function name at all (e.g. "getting home directory is not available"). Partial function name is misleading IMO.
return NULL; }
Michal
From: Laine Stump <laine@redhat.com> This will make it easier to, e.g., add sanity checks to the Linux versions of these functions without potentially causing regressions on a platform that isn't widely tested Signed-off-by: Laine Stump <laine@redhat.com> --- src/util/virutil.c | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index 3c0d04c3d7..b40229c7cf 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -588,43 +588,64 @@ virGetHostnameQuiet(void) } + +#ifdef WIN32 + + char * virGetUserHomeDirectory(void) { return g_strdup(g_get_home_dir()); } - char *virGetUserConfigDirectory(void) { -#ifdef WIN32 return g_strdup(g_get_user_config_dir()); -#else - return g_build_filename(g_get_user_config_dir(), "libvirt", NULL); -#endif } char *virGetUserCacheDirectory(void) { -#ifdef WIN32 return g_strdup(g_get_user_cache_dir()); -#else - return g_build_filename(g_get_user_cache_dir(), "libvirt", NULL); -#endif } char *virGetUserRuntimeDirectory(void) { -#ifdef WIN32 return g_strdup(g_get_user_runtime_dir()); -#else +} + + +#else /* !WIN32 */ + + +char * +virGetUserHomeDirectory(void) +{ + return g_strdup(g_get_home_dir()); +} + +char *virGetUserConfigDirectory(void) +{ + return g_build_filename(g_get_user_config_dir(), "libvirt", NULL); +} + + +char *virGetUserCacheDirectory(void) +{ + return g_build_filename(g_get_user_cache_dir(), "libvirt", NULL); +} + + +char *virGetUserRuntimeDirectory(void) +{ return g_build_filename(g_get_user_runtime_dir(), "libvirt", NULL); -#endif } +#endif /* !WIN32 */ + + #ifdef WITH_GETPWUID_R /* Look up fields from the user database for the given user. On * error, set errno, report the error if not instructed otherwise via @quiet, -- 2.52.0
From: Laine Stump <laine@redhat.com> We've been using glib g_setenv() since commit 2c3353242337bb50fe5abc9454fd5fc98236d4ef in December 2019 (switching away from the gnulib version of setenv()). Most (but not all) of the calls to get environment variables have remained using libc's getenv() though, even though there is a g_getenv() wrapper in glib to match the g_setenv() wrapper. While getenv() doesn't have the thread safety problems of setenv(), it's still recommended that users of g_setenv() also use g_getenv() (for consistency, and because the glib functions handle UTF-8 properly while libc getenv() may or may not depending on the setting of LANG in the environment). This patch changes all calls to getenv() to use g_getenv() instead, with the exceptions of: 1) the call to getenv() in virt-login-shell.c (because virt-login-shell runs setuid root, and we don't want glib or any other gigantic library anywhere near a setuid program). In a few cases a char * needs to be made const, and the return from getenv() needs to be g_strdup()ed if it must stick around for any amount of time (since the buffer returned from g_getenv() might be recycled/re-used if there is another call to g_getenv()/g_setenv()). 2) the call to getenv() in libvirt_nss_log.c because it is compiled into a loadable module that will be loaded into a process after the process's normal startup, and so any initialization that might be required for a glib function to operate properly may not be called. Signed-off-by: Laine Stump <laine@redhat.com> --- scripts/rpcgen/tests/test_demo.c | 2 +- src/admin/libvirt-admin.c | 2 +- src/hyperv/hyperv_driver.c | 2 +- src/libvirt.c | 2 +- src/network/leaseshelper.c | 14 +++++++------- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_interop_config.c | 2 +- src/remote/remote_sockets.c | 4 ++-- src/rpc/virnetlibsshsession.c | 2 +- src/rpc/virnettlscontext.c | 2 +- src/util/virauth.c | 2 +- src/util/vircommand.c | 2 +- src/util/virfile.c | 4 ++-- src/util/virlease.c | 4 ++-- src/util/virlog.c | 6 +++--- src/util/virsystemd.c | 8 ++++---- src/vbox/vbox_XPCOMCGlue.c | 2 +- src/vbox/vbox_common.c | 2 +- tests/eventtest.c | 2 +- tests/fdstreamtest.c | 2 +- tests/qemucpumock.c | 2 +- tests/qemusecuritymock.c | 16 ++++++++-------- tests/securityselinuxhelper.c | 10 +++++----- tests/testutils.c | 16 ++++++++-------- tests/testutils.h | 2 +- tests/testutilsqemu.c | 2 +- tests/vircgroupmock.c | 10 +++++----- tests/virfilemock.c | 8 ++++---- tests/virhostdevtest.c | 2 +- tests/virmockstathelpers.c | 2 +- tests/virnetdaemontest.c | 2 +- tests/virnettlshelpers.c | 2 +- tests/virpcimock.c | 2 +- tests/virportallocatormock.c | 4 ++-- tests/virscsitest.c | 2 +- tests/virsystemdtest.c | 14 +++++++------- tests/virtestmock.c | 6 +++--- tools/virsh.c | 2 +- tools/virt-login-shell-helper.c | 2 +- tools/vsh.c | 12 ++++++------ 40 files changed, 93 insertions(+), 93 deletions(-) diff --git a/scripts/rpcgen/tests/test_demo.c b/scripts/rpcgen/tests/test_demo.c index 82eda89592..bbf00e88a5 100644 --- a/scripts/rpcgen/tests/test_demo.c +++ b/scripts/rpcgen/tests/test_demo.c @@ -41,7 +41,7 @@ static void test_xdr(xdrproc_t proc, void *vorig, void *vnew, const char *testna actlen = xdr_getpos(&xdr); - if (getenv("VIR_TEST_REGENERATE_OUTPUT")) { + if (g_getenv("VIR_TEST_REGENERATE_OUTPUT")) { g_file_set_contents(expfile, buf, actlen, NULL); } diff --git a/src/admin/libvirt-admin.c b/src/admin/libvirt-admin.c index d7efac025f..eebe701fae 100644 --- a/src/admin/libvirt-admin.c +++ b/src/admin/libvirt-admin.c @@ -163,7 +163,7 @@ getSocketPath(virURI *uri) static int virAdmGetDefaultURI(virConf *conf, char **uristr) { - const char *defname = getenv("LIBVIRT_ADMIN_DEFAULT_URI"); + const char *defname = g_getenv("LIBVIRT_ADMIN_DEFAULT_URI"); if (defname && *defname) { *uristr = g_strdup(defname); VIR_DEBUG("Using LIBVIRT_ADMIN_DEFAULT_URI '%s'", *uristr); diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index b01b4919fe..5f51644e52 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -2461,7 +2461,7 @@ hypervDomainScreenshot(virDomainPtr domain, ppmBuffer[i * 3 + 2] = (blueFive * 527 + 23) >> 6; } - temporaryDirectory = getenv("TMPDIR"); + temporaryDirectory = g_getenv("TMPDIR"); if (!temporaryDirectory) temporaryDirectory = "/tmp"; temporaryFile = g_strdup_printf("%s/libvirt.hyperv.screendump.XXXXXX", temporaryDirectory); diff --git a/src/libvirt.c b/src/libvirt.c index 375d3fa7ef..b38d21575a 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -881,7 +881,7 @@ static int virConnectGetDefaultURI(virConf *conf, char **name) { - const char *defname = getenv("LIBVIRT_DEFAULT_URI"); + const char *defname = g_getenv("LIBVIRT_DEFAULT_URI"); if (defname && *defname) { VIR_DEBUG("Using LIBVIRT_DEFAULT_URI '%s'", defname); *name = g_strdup(defname); diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c index 8206712e12..66a1003785 100644 --- a/src/network/leaseshelper.c +++ b/src/network/leaseshelper.c @@ -84,10 +84,10 @@ main(int argc, char **argv) const char *ip = NULL; const char *mac = NULL; g_autofree char *leases_str = NULL; - const char *iaid = getenv("DNSMASQ_IAID"); - const char *clientid = getenv("DNSMASQ_CLIENT_ID"); - const char *interface = getenv("DNSMASQ_INTERFACE"); - const char *hostname = getenv("DNSMASQ_SUPPLIED_HOSTNAME"); + const char *iaid = g_getenv("DNSMASQ_IAID"); + const char *clientid = g_getenv("DNSMASQ_CLIENT_ID"); + const char *interface = g_getenv("DNSMASQ_INTERFACE"); + const char *hostname = g_getenv("DNSMASQ_SUPPLIED_HOSTNAME"); g_autofree char *server_duid = NULL; int action = -1; int pid_file_fd = -1; @@ -128,7 +128,7 @@ main(int argc, char **argv) * events for expired leases. So, libvirtd sets another env var for this * purpose */ if (!interface && - !(interface = getenv("VIR_BRIDGE_NAME"))) { + !(interface = g_getenv("VIR_BRIDGE_NAME"))) { fprintf(stderr, _("interface not set\n")); exit(EXIT_FAILURE); } @@ -147,11 +147,11 @@ main(int argc, char **argv) /* Check if it is an IPv6 lease */ if (iaid) { - mac = getenv("DNSMASQ_MAC"); + mac = g_getenv("DNSMASQ_MAC"); clientid = argv[2]; } - server_duid = g_strdup(getenv("DNSMASQ_SERVER_DUID")); + server_duid = g_strdup(g_getenv("DNSMASQ_SERVER_DUID")); custom_lease_file = g_strdup_printf(LOCALSTATEDIR "/lib/libvirt/dnsmasq/%s.status", interface); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index a742998e4c..61e1c4b575 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8229,7 +8229,7 @@ qemuBuildAudioPipewireAudioEnv(virCommand *cmd, virCommandAddEnvPair(cmd, "PIPEWIRE_RUNTIME_DIR", runtimeDir); } else { for (i = 0; i < G_N_ELEMENTS(envVars); i++) { - const char *value = getenv(envVars[i]); + const char *value = g_getenv(envVars[i]); if (!value) continue; diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c index 2280b8a2df..3f7b30f8e0 100644 --- a/src/qemu/qemu_interop_config.c +++ b/src/qemu/qemu_interop_config.c @@ -102,7 +102,7 @@ qemuInteropFetchConfigs(const char *name, * much sense to parse files in root's home directory. It * makes sense only for session daemon which runs under * regular user. */ - xdgConfig = g_strdup(getenv("XDG_CONFIG_HOME")); + xdgConfig = g_strdup(g_getenv("XDG_CONFIG_HOME")); if (!xdgConfig) { g_autofree char *home = virGetUserHomeDirectory(); diff --git a/src/remote/remote_sockets.c b/src/remote/remote_sockets.c index 13b760355b..b00705cd21 100644 --- a/src/remote/remote_sockets.c +++ b/src/remote/remote_sockets.c @@ -55,7 +55,7 @@ remoteGetDaemonPathEnv(void) * but if it is not set we will fallback to LIBVIRTD_PATH * for previous behaviour */ - if (getenv("VIRTD_PATH") != NULL) { + if (g_getenv("VIRTD_PATH") != NULL) { return "VIRTD_PATH"; } else { return "LIBVIRTD_PATH"; @@ -440,7 +440,7 @@ remoteGetURIDaemonInfo(virURI *uri, remoteDriverTransport transport, unsigned int *flags) { - const char *autostart_str = getenv("LIBVIRT_AUTOSTART"); + const char *autostart_str = g_getenv("LIBVIRT_AUTOSTART"); *flags = 0; diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index e496d3334e..2f590ec1c4 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -161,7 +161,7 @@ virNetLibsshSessionOnceInit(void) ssh_set_log_level(TRACE_LIBSSH); #endif - dbgLevelStr = getenv("LIBVIRT_LIBSSH_DEBUG"); + dbgLevelStr = g_getenv("LIBVIRT_LIBSSH_DEBUG"); if (dbgLevelStr && virStrToLong_i(dbgLevelStr, NULL, 10, &dbgLevel) >= 0) ssh_set_log_level(dbgLevel); diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c index dfe793e5db..5fed5c71b5 100644 --- a/src/rpc/virnettlscontext.c +++ b/src/rpc/virnettlscontext.c @@ -827,7 +827,7 @@ void virNetTLSSessionDispose(void *obj) void virNetTLSInit(void) { const char *gnutlsdebug; - if ((gnutlsdebug = getenv("LIBVIRT_GNUTLS_DEBUG")) != NULL) { + if ((gnutlsdebug = g_getenv("LIBVIRT_GNUTLS_DEBUG")) != NULL) { int val; if (virStrToLong_i(gnutlsdebug, NULL, 10, &val) < 0) val = 10; diff --git a/src/util/virauth.c b/src/util/virauth.c index e7a5f7f010..fd4b13de7a 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -42,7 +42,7 @@ virAuthGetConfigFilePathURI(virURI *uri, char **path) { size_t i; - const char *authenv = getenv("LIBVIRT_AUTH_FILE"); + const char *authenv = g_getenv("LIBVIRT_AUTH_FILE"); g_autofree char *userdir = NULL; *path = NULL; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 1390c80a32..e871d572a6 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1429,7 +1429,7 @@ virCommandAddEnvPass(virCommand *cmd, const char *name) if (virCommandHasError(cmd)) return; - value = getenv(name); + value = g_getenv(name); if (value) virCommandAddEnvPair(cmd, name, value); } diff --git a/src/util/virfile.c b/src/util/virfile.c index 65b04beb8c..91d5853481 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1912,7 +1912,7 @@ virFileFindResourceFull(const char *filename, const char *envname) { char *ret = NULL; - const char *envval = envname ? getenv(envname) : NULL; + const char *envval = envname ? g_getenv(envname) : NULL; const char *path; g_autofree char *fullFilename = NULL; @@ -1977,7 +1977,7 @@ virFileActivateDirOverrideForProg(const char *argv0) void virFileActivateDirOverrideForLib(void) { - if (getenv("LIBVIRT_DIR_OVERRIDE") != NULL) + if (g_getenv("LIBVIRT_DIR_OVERRIDE") != NULL) useDirOverride = true; } diff --git a/src/util/virlease.c b/src/util/virlease.c index 6fd7b88d88..a8d53efe5b 100644 --- a/src/util/virlease.c +++ b/src/util/virlease.c @@ -208,13 +208,13 @@ virLeaseNew(virJSONValue **lease_ret, const char *server_duid) { g_autoptr(virJSONValue) lease_new = NULL; - const char *exptime_tmp = getenv("DNSMASQ_LEASE_EXPIRES"); + const char *exptime_tmp = g_getenv("DNSMASQ_LEASE_EXPIRES"); long long expirytime = 0; g_autofree char *exptime = NULL; /* In case hostname is still unknown, use the last known one */ if (!hostname) - hostname = getenv("DNSMASQ_OLD_HOSTNAME"); + hostname = g_getenv("DNSMASQ_OLD_HOSTNAME"); if (!mac) return 0; diff --git a/src/util/virlog.c b/src/util/virlog.c index 2d262d94f0..c24dfa83c4 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -1214,18 +1214,18 @@ virLogSetFromEnv(void) if (virLogInitialize() < 0) return -1; - debugEnv = getenv("LIBVIRT_DEBUG"); + debugEnv = g_getenv("LIBVIRT_DEBUG"); if (debugEnv && *debugEnv) { int priority = virLogParseDefaultPriority(debugEnv); if (priority < 0 || virLogSetDefaultPriority(priority) < 0) return -1; } - debugEnv = getenv("LIBVIRT_LOG_FILTERS"); + debugEnv = g_getenv("LIBVIRT_LOG_FILTERS"); if (debugEnv && *debugEnv && virLogSetFilters(debugEnv)) return -1; - debugEnv = getenv("LIBVIRT_LOG_OUTPUTS"); + debugEnv = g_getenv("LIBVIRT_LOG_OUTPUTS"); if (debugEnv && *debugEnv && virLogSetOutputs(debugEnv)) return -1; diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index bd174c683e..faac8b37e3 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -666,7 +666,7 @@ virSystemdNotify(const char *msg) VIR_DEBUG("Notify '%s'", msg); - if (!(path = getenv("NOTIFY_SOCKET"))) { + if (!(path = g_getenv("NOTIFY_SOCKET"))) { VIR_DEBUG("Skipping systemd notify, not requested"); return; } @@ -891,7 +891,7 @@ virSystemdGetListenFDs(void) VIR_DEBUG("Setting up networking from caller"); - if (!(pidstr = getenv("LISTEN_PID"))) { + if (!(pidstr = g_getenv("LISTEN_PID"))) { VIR_DEBUG("No LISTEN_PID from caller"); return 0; } @@ -907,7 +907,7 @@ virSystemdGetListenFDs(void) return 0; } - if (!(fdstr = getenv("LISTEN_FDS"))) { + if (!(fdstr = g_getenv("LISTEN_FDS"))) { VIR_DEBUG("No LISTEN_FDS from caller"); return 0; } @@ -954,7 +954,7 @@ virSystemdActivationNew(int nfds) act->fds = virHashNew(virSystemdActivationEntryFree); - fdnames = getenv("LISTEN_FDNAMES"); + fdnames = g_getenv("LISTEN_FDNAMES"); if (!fdnames) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing LISTEN_FDNAMES env from systemd socket activation")); diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c index e625492173..a67ceb9a00 100644 --- a/src/vbox/vbox_XPCOMCGlue.c +++ b/src/vbox/vbox_XPCOMCGlue.c @@ -181,7 +181,7 @@ VBoxCGlueInit(unsigned int *version) "/usr/local/lib/VirtualBox", "/Applications/VirtualBox.app/Contents/MacOS" }; - const char *home = getenv("VBOX_APP_HOME"); + const char *home = g_getenv("VBOX_APP_HOME"); /* If the user specifies the location, try only that. */ if (home != NULL) { diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index d2a8cf8da4..882f9e1f01 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -3578,7 +3578,7 @@ vboxDumpDisplay(virDomainDef *def, struct _vboxDriver *data, IMachine *machine) graphics = g_new0(virDomainGraphicsDef, 1); graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP; - graphics->data.desktop.display = g_strdup(getenv("DISPLAY")); + graphics->data.desktop.display = g_strdup(g_getenv("DISPLAY")); } if (graphics) diff --git a/tests/eventtest.c b/tests/eventtest.c index 470de4c630..5f78e1fcfe 100644 --- a/tests/eventtest.c +++ b/tests/eventtest.c @@ -323,7 +323,7 @@ mymain(void) size_t i; pthread_t eventThread; char one = '1'; - char *debugEnv = getenv("LIBVIRT_DEBUG"); + const char *debugEnv = g_getenv("LIBVIRT_DEBUG"); for (i = 0; i < NUM_FDS; i++) { if (virPipeQuiet(handles[i].pipeFD) < 0) { diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c index 5e6b347949..9d244681f7 100644 --- a/tests/fdstreamtest.c +++ b/tests/fdstreamtest.c @@ -319,7 +319,7 @@ mymain(void) if (virTestRun("Stream write non-blocking ", testFDStreamWriteNonblock, scratchdir) < 0) ret = -1; - if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL) + if (g_getenv("LIBVIRT_SKIP_CLEANUP") == NULL) virFileDeleteTree(scratchdir); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/qemucpumock.c b/tests/qemucpumock.c index 5a63308347..c85721f448 100644 --- a/tests/qemucpumock.c +++ b/tests/qemucpumock.c @@ -29,7 +29,7 @@ virCPUDef * virQEMUCapsProbeHostCPU(virArch hostArch G_GNUC_UNUSED, virDomainCapsCPUModels *models G_GNUC_UNUSED) { - const char *model = getenv("VIR_TEST_MOCK_FAKE_HOST_CPU"); + const char *model = g_getenv("VIR_TEST_MOCK_FAKE_HOST_CPU"); return testUtilsHostCpusGetDefForModel(model); } diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c index d5c711b5d7..cbd928ab38 100644 --- a/tests/qemusecuritymock.c +++ b/tests/qemusecuritymock.c @@ -231,7 +231,7 @@ int virFileRemoveXAttr(const char *path, #define VIR_MOCK_STAT_HOOK \ do { \ - if (getenv(ENVVAR)) { \ + if (g_getenv(ENVVAR)) { \ uint32_t *val; \ \ virMutexLock(&m); \ @@ -303,7 +303,7 @@ chown(const char *path, uid_t uid, gid_t gid) init_syms(); - if (getenv(ENVVAR)) + if (g_getenv(ENVVAR)) ret = mock_chown(path, uid, gid); else ret = real_chown(path, uid, gid); @@ -319,7 +319,7 @@ open(const char *path, int flags, ...) init_syms(); - if (getenv(ENVVAR)) { + if (g_getenv(ENVVAR)) { ret = 42; /* Some dummy FD */ } else if (flags & O_CREAT) { va_list ap; @@ -344,7 +344,7 @@ __open_2(const char *path, int flags) init_syms(); - if (getenv(ENVVAR)) { + if (g_getenv(ENVVAR)) { ret = 42; /* Some dummy FD */ } else { ret = real___open_2(path, flags); @@ -361,7 +361,7 @@ close(int fd) init_syms(); - if (fd == 42 && getenv(ENVVAR)) + if (fd == 42 && g_getenv(ENVVAR)) ret = 0; else ret = real_close(fd); @@ -392,7 +392,7 @@ bool virFileExists(const char *path) { VIR_LOCK_GUARD lock = virLockGuardLock(&m); - if (getenv(ENVVAR) == NULL) { + if (g_getenv(ENVVAR) == NULL) { init_syms(); return real_virFileExists(path); @@ -640,7 +640,7 @@ setfilecon_raw(const char *path, init_syms(); - if (getenv(ENVVAR)) + if (g_getenv(ENVVAR)) ret = mock_setfilecon_raw(path, context); else ret = real_setfilecon_raw(path, context); @@ -657,7 +657,7 @@ getfilecon_raw(const char *path, init_syms(); - if (getenv(ENVVAR)) + if (g_getenv(ENVVAR)) ret = mock_getfilecon_raw(path, context); else ret = real_getfilecon_raw(path, context); diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c index e5ded96485..be9d03e815 100644 --- a/tests/securityselinuxhelper.c +++ b/tests/securityselinuxhelper.c @@ -92,12 +92,12 @@ int getcon_raw(char **context) errno = EINVAL; return -1; } - if (getenv("FAKE_SELINUX_CONTEXT") == NULL) { + if (g_getenv("FAKE_SELINUX_CONTEXT") == NULL) { *context = NULL; errno = EINVAL; return -1; } - *context = g_strdup(getenv("FAKE_SELINUX_CONTEXT")); + *context = g_strdup(g_getenv("FAKE_SELINUX_CONTEXT")); return 0; } @@ -117,12 +117,12 @@ int getpidcon_raw(pid_t pid, char **context) errno = ESRCH; return -1; } - if (getenv("FAKE_SELINUX_CONTEXT") == NULL) { + if (g_getenv("FAKE_SELINUX_CONTEXT") == NULL) { *context = NULL; errno = EINVAL; return -1; } - *context = g_strdup(getenv("FAKE_SELINUX_CONTEXT")); + *context = g_strdup(g_getenv("FAKE_SELINUX_CONTEXT")); return 0; } @@ -191,7 +191,7 @@ int statfs(const char *path, struct statfs *buf) int is_selinux_enabled(void) { - return getenv("FAKE_SELINUX_DISABLED") == NULL; + return g_getenv("FAKE_SELINUX_DISABLED") == NULL; } int security_getenforce(void) diff --git a/tests/testutils.c b/tests/testutils.c index 3c5c298293..814391b804 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -73,10 +73,10 @@ static int virTestUseTerminalColors(void) static unsigned int virTestGetFlag(const char *name) { - char *flagStr; + const char *flagStr; unsigned int flag; - if ((flagStr = getenv(name)) == NULL) + if ((flagStr = g_getenv(name)) == NULL) return 0; if (virStrToLong_ui(flagStr, NULL, 10, &flag) < 0) @@ -123,7 +123,7 @@ virTestRun(const char *title, /* Some test are fragile about environ settings. If that's * the case, don't poison it. */ - if (getenv("VIR_TEST_MOCK_PROGNAME")) + if (g_getenv("VIR_TEST_MOCK_PROGNAME")) g_setenv("VIR_TEST_MOCK_TESTNAME", title, TRUE); if (testCounter == 0 && !virTestGetVerbose()) @@ -760,7 +760,7 @@ virTestHasRangeBitmap(void) static int virTestSetEnvPath(void) { - const char *path = getenv("PATH"); + const char *path = g_getenv("PATH"); g_autofree char *new_path = NULL; if (path) { @@ -813,7 +813,7 @@ int virTestMain(int argc, const char *lib; va_list ap; int ret; - char *testRange = NULL; + const char *testRange = NULL; size_t noutputs = 0; virLogOutput *output = NULL; virLogOutput **outputs = NULL; @@ -823,7 +823,7 @@ int virTestMain(int argc, g_autofree char *mock = NULL; g_autofree char *fakerootdir = NULL; - if (getenv("VIR_TEST_FILE_ACCESS")) { + if (g_getenv("VIR_TEST_FILE_ACCESS")) { preloads = g_renew(const char *, preloads, npreloads + 2); preloads[npreloads++] = VIR_TEST_MOCK("virtest"); preloads[npreloads] = NULL; @@ -884,7 +884,7 @@ int virTestMain(int argc, if (virLogSetFromEnv() < 0) return EXIT_FAILURE; - if (!getenv("LIBVIRT_DEBUG") && !virLogGetNbOutputs()) { + if (!g_getenv("LIBVIRT_DEBUG") && !virLogGetNbOutputs()) { if (!(output = virLogOutputNew(virtTestLogOutput, virtTestLogClose, &testLog, VIR_LOG_DEBUG, VIR_LOG_TO_STDERR, NULL))) @@ -898,7 +898,7 @@ int virTestMain(int argc, } } - if ((testRange = getenv("VIR_TEST_RANGE")) != NULL) { + if ((testRange = g_getenv("VIR_TEST_RANGE")) != NULL) { if (!(testBitmap = virBitmapParseUnlimited(testRange))) { fprintf(stderr, "Cannot parse range %s\n", testRange); return EXIT_FAILURE; diff --git a/tests/testutils.h b/tests/testutils.h index e22324e06d..e60876bd9e 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -137,7 +137,7 @@ int virTestMain(int argc, #define VIR_TEST_PRELOAD(libs) \ do { \ - const char *preload = getenv(PRELOAD_VAR); \ + const char *preload = g_getenv(PRELOAD_VAR); \ if (preload == NULL || strstr(preload, libs) == NULL) { \ char *newenv; \ char *new_library_path; \ diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 78ec521266..dbff601ce4 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -63,7 +63,7 @@ bool qemuRdpAvailable(const char *helper G_GNUC_UNUSED) bool virTPMSwtpmSetupCapsGet(virTPMSwtpmSetupFeature cap) { - const char *tpmver = getenv(TEST_TPM_ENV_VAR); + const char *tpmver = g_getenv(TEST_TPM_ENV_VAR); switch (cap) { case VIR_TPM_SWTPM_SETUP_FEATURE_TPM_1_2: diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c index a5c18bd7b0..1aa6f047ce 100644 --- a/tests/vircgroupmock.c +++ b/tests/vircgroupmock.c @@ -321,7 +321,7 @@ static int make_controller(const char *path, mode_t mode) bool unified = false; bool hybrid = false; - mock = getenv("VIR_CGROUP_MOCK_MODE"); + mock = g_getenv("VIR_CGROUP_MOCK_MODE"); if (mock) { if (STREQ(mock, "unified")) { unified = true; @@ -344,11 +344,11 @@ static int make_controller(const char *path, mode_t mode) static void init_sysfs(void) { const char *mock; - char *newfakerootdir; + const char *newfakerootdir; bool unified = false; bool hybrid = false; - if (!(newfakerootdir = getenv("LIBVIRT_FAKE_ROOT_DIR"))) { + if (!(newfakerootdir = g_getenv("LIBVIRT_FAKE_ROOT_DIR"))) { fprintf(stderr, "Missing LIBVIRT_FAKE_ROOT_DIR env variable\n"); abort(); } @@ -359,7 +359,7 @@ static void init_sysfs(void) VIR_FREE(fakerootdir); fakerootdir = g_strdup(newfakerootdir); - mock = getenv("VIR_CGROUP_MOCK_MODE"); + mock = g_getenv("VIR_CGROUP_MOCK_MODE"); if (mock) { if (STREQ(mock, "unified")) { unified = true; @@ -421,7 +421,7 @@ FILE *fopen(const char *path, const char *mode) char *filepath = NULL; const char *type = NULL; FILE *rc = NULL; - const char *filename = getenv("VIR_CGROUP_MOCK_FILENAME"); + const char *filename = g_getenv("VIR_CGROUP_MOCK_FILENAME"); init_syms(); diff --git a/tests/virfilemock.c b/tests/virfilemock.c index 5a09cce855..49538dcb71 100644 --- a/tests/virfilemock.c +++ b/tests/virfilemock.c @@ -56,7 +56,7 @@ setmntent(const char *filename, const char *type) init_syms(); - if ((mtab = getenv("LIBVIRT_MTAB"))) + if ((mtab = g_getenv("LIBVIRT_MTAB"))) filename = mtab; return real_setmntent(filename, type); @@ -170,7 +170,7 @@ statfs(const char *path, struct statfs *buf) init_syms(); - if ((mtab = getenv("LIBVIRT_MTAB"))) + if ((mtab = g_getenv("LIBVIRT_MTAB"))) return statfs_mock(mtab, path, buf); return real_statfs(path, buf); @@ -183,7 +183,7 @@ realpath(const char *path, char *resolved) init_syms(); - if (getenv("LIBVIRT_MTAB")) { + if (g_getenv("LIBVIRT_MTAB")) { const char *p; if ((p = STRSKIP(path, "/some/symlink"))) { @@ -208,7 +208,7 @@ realpath(const char *path, char *resolved) int access(const char *path, int mode) { - const char *mtab = getenv("LIBVIRT_MTAB"); + const char *mtab = g_getenv("LIBVIRT_MTAB"); init_syms(); diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index a35c1d9402..b0fb94e197 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -104,7 +104,7 @@ myCleanup(void) virDomainDiskDefFree(disks[i]); if (mgr) { - if (!getenv("LIBVIRT_SKIP_CLEANUP")) + if (!g_getenv("LIBVIRT_SKIP_CLEANUP")) virFileDeleteTree(mgr->stateDir); virObjectUnref(mgr->activePCIHostdevs); diff --git a/tests/virmockstathelpers.c b/tests/virmockstathelpers.c index 8a76c5e369..5b1319cedc 100644 --- a/tests/virmockstathelpers.c +++ b/tests/virmockstathelpers.c @@ -171,7 +171,7 @@ static void virMockStatInit(void) return; init = true; - debug = getenv("VIR_MOCK_STAT_DEBUG"); + debug = g_getenv("VIR_MOCK_STAT_DEBUG"); #ifdef MOCK_STAT # if defined(__APPLE__) && defined(__x86_64__) diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c index 1a5c5f32e1..f2c3ae70ed 100644 --- a/tests/virnetdaemontest.c +++ b/tests/virnetdaemontest.c @@ -377,7 +377,7 @@ mymain(void) * the generated JSON, and replace the file descriptor * numbers with 100, 101, 102, 103. */ - if (getenv("VIR_GENERATE_JSON")) { + if (g_getenv("VIR_GENERATE_JSON")) { char *json = testGenerateJSON(server_names[0]); if (!json) return EXIT_FAILURE; diff --git a/tests/virnettlshelpers.c b/tests/virnettlshelpers.c index ca293eb6d6..620068e495 100644 --- a/tests/virnettlshelpers.c +++ b/tests/virnettlshelpers.c @@ -430,7 +430,7 @@ void testTLSDiscardCert(struct testTLSCertReq *req) g_clear_pointer(&req->crt, gnutls_x509_crt_deinit); - if (getenv("VIRT_TEST_DEBUG_CERTS") == NULL) + if (g_getenv("VIRT_TEST_DEBUG_CERTS") == NULL) unlink(req->filename); } diff --git a/tests/virpcimock.c b/tests/virpcimock.c index ca345f37a3..a5cf0acfc7 100644 --- a/tests/virpcimock.c +++ b/tests/virpcimock.c @@ -981,7 +981,7 @@ init_env(void) .vpd_len = G_N_ELEMENTS(fullVPDExampleData), }; - if (!(fakerootdir = getenv("LIBVIRT_FAKE_ROOT_DIR"))) { + if (!(fakerootdir = g_strdup(g_getenv("LIBVIRT_FAKE_ROOT_DIR")))) { GError *err = NULL; fakerootdir = g_dir_make_tmp(NULL, &err); diff --git a/tests/virportallocatormock.c b/tests/virportallocatormock.c index 964f475944..5fd80c67a0 100644 --- a/tests/virportallocatormock.c +++ b/tests/virportallocatormock.c @@ -57,7 +57,7 @@ int socket(int domain, { init_syms(); - if (getenv("LIBVIRT_TEST_IPV4ONLY") && domain == AF_INET6) { + if (g_getenv("LIBVIRT_TEST_IPV4ONLY") && domain == AF_INET6) { errno = EAFNOSUPPORT; return -1; } @@ -73,7 +73,7 @@ int bind(int sockfd G_GNUC_UNUSED, memcpy(&saddr, addr, sizeof(saddr)); - if (host_has_ipv6 && !getenv("LIBVIRT_TEST_IPV4ONLY")) { + if (host_has_ipv6 && !g_getenv("LIBVIRT_TEST_IPV4ONLY")) { if (saddr.sin_port == htons(5900) || (saddr.sin_family == AF_INET && saddr.sin_port == htons(5904)) || diff --git a/tests/virscsitest.c b/tests/virscsitest.c index 2c3b599c7a..5cd127807f 100644 --- a/tests/virscsitest.c +++ b/tests/virscsitest.c @@ -211,7 +211,7 @@ mymain(void) ret = -1; cleanup: - if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL) + if (g_getenv("LIBVIRT_SKIP_CLEANUP") == NULL) virFileDeleteTree(tmpdir); VIR_FREE(virscsi_prefix); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 24c118a409..b93462ae52 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -61,7 +61,7 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, VIR_MOCK_REAL_INIT(g_dbus_connection_call_sync); if (STREQ(bus_name, "org.freedesktop.machine1")) { - if (getenv("FAIL_BAD_SERVICE")) { + if (g_getenv("FAIL_BAD_SERVICE")) { *error = g_dbus_error_new_for_dbus_error( "org.freedesktop.systemd.badthing", "Something went wrong creating the machine"); @@ -90,11 +90,11 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, } else if (STREQ(bus_name, "org.freedesktop.resolve1")) { g_autofree char *actual = NULL; - if (getenv("FAIL_BAD_SERVICE")) { + if (g_getenv("FAIL_BAD_SERVICE")) { *error = g_dbus_error_new_for_dbus_error("org.freedesktop.systemd.badthing", "Contacting resolved failed"); } else if (STREQ(method_name, "SetLinkDomains")) { - const char *expected = getenv("TEST_RESOLVED_LINK_DOMAINS"); + const char *expected = g_getenv("TEST_RESOLVED_LINK_DOMAINS"); actual = g_variant_print(params, FALSE); if (virTestCompareToString(expected, actual) < 0) @@ -103,7 +103,7 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, else reply = g_variant_new("()"); } else if (STREQ(method_name, "SetLinkDNS")) { - const char *expected = getenv("TEST_RESOLVED_LINK_DNS"); + const char *expected = g_getenv("TEST_RESOLVED_LINK_DNS"); actual = g_variant_print(params, FALSE); if (virTestCompareToString(expected, actual) < 0) @@ -116,7 +116,7 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, "Unknown resolved method"); } } else if (STREQ(bus_name, "org.freedesktop.login1")) { - reply = g_variant_new("(s)", getenv("RESULT_SUPPORT")); + reply = g_variant_new("(s)", g_getenv("RESULT_SUPPORT")); } else if (STREQ(bus_name, "org.freedesktop.DBus") && STREQ(method_name, "ListActivatableNames")) { GVariantBuilder builder; @@ -125,7 +125,7 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, g_variant_builder_add(&builder, "s", "org.foo.bar.wizz"); - if (!getenv("FAIL_NO_SERVICE")) { + if (!g_getenv("FAIL_NO_SERVICE")) { g_variant_builder_add(&builder, "s", "org.freedesktop.machine1"); g_variant_builder_add(&builder, "s", "org.freedesktop.login1"); g_variant_builder_add(&builder, "s", "org.freedesktop.resolve1"); @@ -140,7 +140,7 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, g_variant_builder_add(&builder, "s", "org.foo.bar.wizz"); - if (!getenv("FAIL_NO_SERVICE") && !getenv("FAIL_NOT_REGISTERED")) { + if (!g_getenv("FAIL_NO_SERVICE") && !g_getenv("FAIL_NOT_REGISTERED")) { g_variant_builder_add(&builder, "s", "org.freedesktop.systemd1"); g_variant_builder_add(&builder, "s", "org.freedesktop.login1"); g_variant_builder_add(&builder, "s", "org.freedesktop.resolve1"); diff --git a/tests/virtestmock.c b/tests/virtestmock.c index a5c3b29f39..5610ef46f6 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -64,15 +64,15 @@ printFile(const char *file, const char *func) { FILE *fp; - const char *testname = getenv("VIR_TEST_MOCK_TESTNAME"); + const char *testname = g_getenv("VIR_TEST_MOCK_TESTNAME"); if (!progname) { - progname = getenv("VIR_TEST_MOCK_PROGNAME"); + progname = g_getenv("VIR_TEST_MOCK_PROGNAME"); if (!progname) return; - output = getenv("VIR_TEST_FILE_ACCESS_OUTPUT"); + output = g_getenv("VIR_TEST_FILE_ACCESS_OUTPUT"); if (!output) output = VIR_FILE_ACCESS_DEFAULT; } diff --git a/tools/virsh.c b/tools/virsh.c index 643ef6b453..fdce3220b3 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -894,7 +894,7 @@ main(int argc, char **argv) } if (!ctl->connname) - ctl->connname = g_strdup(getenv("VIRSH_DEFAULT_CONNECT_URI")); + ctl->connname = g_strdup(g_getenv("VIRSH_DEFAULT_CONNECT_URI")); if (!ctl->imode) { ret = vshCommandRun(ctl, ctl->cmd); diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helper.c index a1c68a1afa..9fe34f55f1 100644 --- a/tools/virt-login-shell-helper.c +++ b/tools/virt-login-shell-helper.c @@ -357,7 +357,7 @@ main(int argc, char **argv) /* We're duping the string because the clearenv() * call will shortly release the pointer we get * back from getenv() right here */ - term = g_strdup(getenv("TERM")); + term = g_strdup(g_getenv("TERM")); /* A fork is required to create new process in correct pid namespace. */ if ((cpid = virFork()) < 0) diff --git a/tools/vsh.c b/tools/vsh.c index 18914cc818..74016c0043 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2567,7 +2567,7 @@ vshEditWriteToTempFile(vshControl *ctl, const char *doc) const char *tmpdir; VIR_AUTOCLOSE fd = -1; - tmpdir = getenv("TMPDIR"); + tmpdir = g_getenv("TMPDIR"); if (!tmpdir) tmpdir = "/tmp"; filename = g_strdup_printf("%s/virshXXXXXX.xml", tmpdir); @@ -2611,9 +2611,9 @@ vshEditFile(vshControl *ctl, const char *filename) int outfd = STDOUT_FILENO; int errfd = STDERR_FILENO; - editor = getenv("VISUAL"); + editor = g_getenv("VISUAL"); if (!editor) - editor = getenv("EDITOR"); + editor = g_getenv("EDITOR"); if (!editor) editor = DEFAULT_EDITOR; @@ -3044,7 +3044,7 @@ vshReadlineInit(vshControl *ctl) histsize_env = g_strdup_printf("%s_HISTSIZE", ctl->env_prefix); /* Limit the total size of the history buffer */ - if ((histsize_str = getenv(histsize_env))) { + if ((histsize_str = g_getenv(histsize_env))) { if (virStrToLong_i(histsize_str, NULL, 10, &max_history) < 0) { vshError(ctl, _("Bad $%1$s value."), histsize_env); return -1; @@ -3157,7 +3157,7 @@ vshInitDebug(vshControl *ctl) g_autofree char *env = g_strdup_printf("%s_DEBUG", ctl->env_prefix); /* log level not set from commandline, check env variable */ - debugEnv = getenv(env); + debugEnv = g_getenv(env); if (debugEnv) { int debug; if (virStrToLong_i(debugEnv, NULL, 10, &debug) < 0 || @@ -3174,7 +3174,7 @@ vshInitDebug(vshControl *ctl) g_autofree char *env = g_strdup_printf("%s_LOG_FILE", ctl->env_prefix); /* log file not set from cmdline */ - debugEnv = getenv(env); + debugEnv = g_getenv(env); if (debugEnv && *debugEnv) { ctl->logfile = g_strdup(debugEnv); vshOpenLogFile(ctl); -- 2.52.0
On 2/24/26 09:22, Laine Stump via Devel wrote:
From: Laine Stump <laine@redhat.com>
We've been using glib g_setenv() since commit 2c3353242337bb50fe5abc9454fd5fc98236d4ef in December 2019 (switching away from the gnulib version of setenv()). Most (but not all) of the calls to get environment variables have remained using libc's getenv() though, even though there is a g_getenv() wrapper in glib to match the g_setenv() wrapper.
While getenv() doesn't have the thread safety problems of setenv(), it's still recommended that users of g_setenv() also use g_getenv() (for consistency, and because the glib functions handle UTF-8 properly while libc getenv() may or may not depending on the setting of LANG in the environment).
This patch changes all calls to getenv() to use g_getenv() instead, with the exceptions of:
1) the call to getenv() in virt-login-shell.c (because virt-login-shell runs setuid root, and we don't want glib or any other gigantic library anywhere near a setuid program). In a few cases a char * needs to be made const, and the return from getenv() needs to be g_strdup()ed if it must stick around for any amount of time (since the buffer returned from g_getenv() might be recycled/re-used if there is another call to g_getenv()/g_setenv()).
2) the call to getenv() in libvirt_nss_log.c because it is compiled into a loadable module that will be loaded into a process after the process's normal startup, and so any initialization that might be required for a glib function to operate properly may not be called.
Signed-off-by: Laine Stump <laine@redhat.com> --- scripts/rpcgen/tests/test_demo.c | 2 +- src/admin/libvirt-admin.c | 2 +- src/hyperv/hyperv_driver.c | 2 +- src/libvirt.c | 2 +- src/network/leaseshelper.c | 14 +++++++------- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_interop_config.c | 2 +- src/remote/remote_sockets.c | 4 ++-- src/rpc/virnetlibsshsession.c | 2 +- src/rpc/virnettlscontext.c | 2 +- src/util/virauth.c | 2 +- src/util/vircommand.c | 2 +- src/util/virfile.c | 4 ++-- src/util/virlease.c | 4 ++-- src/util/virlog.c | 6 +++--- src/util/virsystemd.c | 8 ++++---- src/vbox/vbox_XPCOMCGlue.c | 2 +- src/vbox/vbox_common.c | 2 +- tests/eventtest.c | 2 +- tests/fdstreamtest.c | 2 +- tests/qemucpumock.c | 2 +- tests/qemusecuritymock.c | 16 ++++++++-------- tests/securityselinuxhelper.c | 10 +++++----- tests/testutils.c | 16 ++++++++-------- tests/testutils.h | 2 +- tests/testutilsqemu.c | 2 +- tests/vircgroupmock.c | 10 +++++----- tests/virfilemock.c | 8 ++++---- tests/virhostdevtest.c | 2 +- tests/virmockstathelpers.c | 2 +- tests/virnetdaemontest.c | 2 +- tests/virnettlshelpers.c | 2 +- tests/virpcimock.c | 2 +- tests/virportallocatormock.c | 4 ++-- tests/virscsitest.c | 2 +- tests/virsystemdtest.c | 14 +++++++------- tests/virtestmock.c | 6 +++--- tools/virsh.c | 2 +- tools/virt-login-shell-helper.c | 2 +- tools/vsh.c | 12 ++++++------ 40 files changed, 93 insertions(+), 93 deletions(-)
Missed one: src/secret/secret_config.c: credentialsDirectory = getenv("CREDENTIALS_DIRECTORY"); Michal
From: Laine Stump <laine@redhat.com> A long time ago we added some lines to "poison" the environment of test programs (specifically $HOME and $XDG_*) with nonexisting unusable paths so that any test program attempting to use the normal settings of those variables (which point into the filesystem of the system running the test) would fail (rather than silently messing up the test system). At some later time, someone wrote tests for hostdev devices that required that virGetUserRuntimeDirectory() (which normally uses either $XDG_RUNTIME_DIR or $HOME) return a directory that could actually be used as a part of the test; this was solved by mocking virGetUserRuntimeDirectory() to return a path underneath $LIBVIRT_FAKE_ROOT_DIR (which is created each time a test starts). Much much later, I wanted to add validation of the directory returned by virGetUserRuntimeDirectory(), but when this validation was added, the poisoned values that had been set (back in paragraph one "a long time ago") caused this validation to fail. My first attempt to fix this was to make the mocked virGetUserRuntimeDirectory() more generally available, and turn it on for all the tests that failed. But then I realized that a better solution would be to instead "nourish" (rather than "poison" - get it?) $HOME and $XDG_* with directories created under $LIBVIRT_FAKE_ROOT_DIR. This way we are actually testing the real virGetUserRuntimeDirectory() and any future validation, and also make some other tests cover more actual code in the future. In this patch the poisoning of the environment is removed, the call to the function creating the fake root dir is moved up to that location, and as a part of creating the fake root dir, we also set the aforementioned environment variables and create the directories associated with them (since the tests assume that they already exist). The now-redundant original mock of virGetUserRuntimeDirectory() will be removed in another patch. Signed-off-by: Laine Stump <laine@redhat.com> --- tests/testutils.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/tests/testutils.c b/tests/testutils.c index 814391b804..c984f66d0e 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -779,6 +779,20 @@ virTestSetEnvPath(void) #define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX" +static int +virTestFakeEnvSubDirInit(const char *envName, const char *fakeRootName, const char *fakeSubDirName) +{ + g_autofree char *envVal = g_build_filename(fakeRootName, fakeSubDirName, NULL); + + if (g_mkdir(envVal, 0777) < 0) { + fprintf(stderr, "Cannot create fake %s directory at %s", envName, envVal); + return -1; + } + + g_setenv(envName, envVal, TRUE); + return 0; +} + char* virTestFakeRootDirInit(void) { @@ -791,6 +805,22 @@ virTestFakeRootDirInit(void) g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE); + /* the glib g_get_user_*_dir() functions use these environment variables to + * determine locations for various data/log/config files. Setting them here + * will assure that code under test that is using those directories won't pollute + * the system under test. + */ + if (virTestFakeEnvSubDirInit("HOME", fakerootdir, "home") < 0) + return NULL; + if (virTestFakeEnvSubDirInit("XDG_RUNTIME_DIR", fakerootdir, "user-runtime-dir") < 0) + return NULL; + if (virTestFakeEnvSubDirInit("XDG_DATA_HOME", fakerootdir, "user-data-home") < 0) + return NULL; + if (virTestFakeEnvSubDirInit("XDG_CACHE_HOME", fakerootdir, "user-cache-home") < 0) + return NULL; + if (virTestFakeEnvSubDirInit("XDG_CONFIG_HOME", fakerootdir, "user-config-home") < 0) + return NULL; + return g_steal_pointer(&fakerootdir); } @@ -829,11 +859,8 @@ int virTestMain(int argc, preloads[npreloads] = NULL; } - g_setenv("HOME", "/bad-test-used-env-home", TRUE); - g_setenv("XDG_RUNTIME_DIR", "/bad-test-used-env-xdg-runtime-dir", TRUE); - g_setenv("XDG_DATA_HOME", "/bad-test-used-env-xdg-data-home", TRUE); - g_setenv("XDG_CACHE_HOME", "/bad-test-used-env-xdg-cache-home", TRUE); - g_setenv("XDG_CONFIG_HOME", "/bad-test-used-env-xdg-config-home", TRUE); + if (!(fakerootdir = virTestFakeRootDirInit())) + return EXIT_FAILURE; va_start(ap, func); while ((lib = va_arg(ap, const char *))) { @@ -907,9 +934,6 @@ int virTestMain(int argc, failedTests = virBitmapNew(1); - if (!(fakerootdir = virTestFakeRootDirInit())) - return EXIT_FAILURE; - ret = (func)(); virResetLastError(); -- 2.52.0
From: Laine Stump <laine@redhat.com> The same functionality has been achieved by setting the XDG_RUNTIME_DIR environment variable during the setup of the "fake root" directory in testutils.c Signed-off-by: Laine Stump <laine@redhat.com> --- tests/meson.build | 1 - tests/qemuhotplugtest.c | 1 - tests/virhostdevmock.c | 15 --------------- tests/virhostdevtest.c | 1 - 4 files changed, 18 deletions(-) delete mode 100644 tests/virhostdevmock.c diff --git a/tests/meson.build b/tests/meson.build index b28ad4a65b..847538d2e4 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -78,7 +78,6 @@ mock_libs = [ { 'name': 'virfilecachemock' }, { 'name': 'virfirewallmock' }, { 'name': 'virhostcpumock' }, - { 'name': 'virhostdevmock' }, { 'name': 'virnetdaemonmock' }, { 'name': 'virnetdevmock' }, { 'name': 'virnetserverclientmock' }, diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 58413b6e0d..0cd738ae3d 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -799,7 +799,6 @@ mymain(void) } VIR_TEST_MAIN_PRELOAD(mymain, - VIR_TEST_MOCK("virhostdev"), VIR_TEST_MOCK("virpci"), VIR_TEST_MOCK("domaincaps"), VIR_TEST_MOCK("virprocess"), diff --git a/tests/virhostdevmock.c b/tests/virhostdevmock.c deleted file mode 100644 index 9b0e4dc2b0..0000000000 --- a/tests/virhostdevmock.c +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 2020 Red Hat, Inc. - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#include <config.h> - -#include "virutil.h" - -char * -virGetUserRuntimeDirectory(void) -{ - return g_build_filename(g_getenv("LIBVIRT_FAKE_ROOT_DIR"), - "user-runtime-directory", NULL); -} diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index b0fb94e197..d52d549feb 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -613,7 +613,6 @@ mymain(void) } VIR_TEST_MAIN_PRELOAD(mymain, - VIR_TEST_MOCK("virhostdev"), VIR_TEST_MOCK("virpci")) #else int -- 2.52.0
On 2/24/26 09:22, Laine Stump via Devel wrote:
These patches were all the result of a failed attempt to provide more useful error messages when libvirt is started with an insufficiently setup environment (e.g. $HOME isn't set and/or the XDG_* environment variables aren't set) which currently results in unhelpful log messages (for an example see https://issues.redhat.com/browse/RHEL-105490). The way I was trying to improve the log messages didn't work out the way I'd hoped (long story), but these patches are generally good (or, for the last two, at least are fodder for discussion).
You can put them into 3 categories:
1) reducing the scope of some autofree strings / renaming functions 2) consistently use g_getenv/g_setenv 3) stop mocking virGetUserRuntimeDirectory in tests, and instead point the environment at a properly initialiazed test directory tree.
(I suppose I could have sent them in separate threads, but they were all in a single branch so sending them together created less "local bureacracy")
Laine Stump (8): util: reduce scope/autofree-ify rundir in virDaemonUnixSocketPaths() util: reduce scope of rundir in virPidFileConstructPath() remote: reduce scope of userdir in remoteGetUNIXSocketHelper() util: rename virGetUserDirectory(ByUID) to virGetUserHomeDirectory(ByUID) util: make completely separate functions for WIN32 versions of virGetUser*Directory() consistently use glib g_getenv() instead of libc getenv() tests: point $HOME and $XDG_* into usable fake root directory tests: stop mocking virGetUserRuntimeDirectory()
scripts/rpcgen/tests/test_demo.c | 2 +- src/admin/libvirt-admin.c | 2 +- src/hyperv/hyperv_driver.c | 2 +- src/libvirt.c | 2 +- src/libvirt_private.syms | 4 +-- src/network/leaseshelper.c | 14 ++++---- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_interop_config.c | 4 +-- src/remote/remote_sockets.c | 7 ++-- src/rpc/virnetclient.c | 4 +-- src/rpc/virnetlibsshsession.c | 2 +- src/rpc/virnettlsconfig.c | 2 +- src/rpc/virnettlscontext.c | 2 +- src/util/virauth.c | 2 +- src/util/vircommand.c | 2 +- src/util/virdaemon.c | 13 ++------ src/util/virfile.c | 4 +-- src/util/virlease.c | 4 +-- src/util/virlog.c | 6 ++-- src/util/virpidfile.c | 4 +-- src/util/virsystemd.c | 8 ++--- src/util/virutil.c | 55 +++++++++++++++++++++---------- src/util/virutil.h | 4 +-- src/vbox/vbox_XPCOMCGlue.c | 2 +- src/vbox/vbox_common.c | 2 +- src/vbox/vbox_storage.c | 2 +- tests/eventtest.c | 2 +- tests/fdstreamtest.c | 2 +- tests/meson.build | 1 - tests/qemucpumock.c | 2 +- tests/qemuhotplugtest.c | 1 - tests/qemusecuritymock.c | 16 ++++----- tests/securityselinuxhelper.c | 10 +++--- tests/testutils.c | 56 +++++++++++++++++++++++--------- tests/testutils.h | 2 +- tests/testutilsqemu.c | 2 +- tests/vircgroupmock.c | 10 +++--- tests/virfilemock.c | 8 ++--- tests/virhostdevmock.c | 15 --------- tests/virhostdevtest.c | 3 +- tests/virmockstathelpers.c | 2 +- tests/virnetdaemontest.c | 2 +- tests/virnettlshelpers.c | 2 +- tests/virpcimock.c | 2 +- tests/virportallocatormock.c | 4 +-- tests/virscsitest.c | 2 +- tests/virsystemdtest.c | 14 ++++---- tests/virtestmock.c | 6 ++-- tools/virsh.c | 2 +- tools/virt-login-shell-helper.c | 4 +-- tools/vsh.c | 14 ++++---- 51 files changed, 179 insertions(+), 162 deletions(-) delete mode 100644 tests/virhostdevmock.c
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
Laine Stump -
Michal Prívozník