]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
consistently use glib g_getenv() instead of libc getenv()
authorLaine Stump <laine@redhat.com>
Mon, 15 Dec 2025 20:56:47 +0000 (15:56 -0500)
committerLaine Stump <laine@redhat.com>
Mon, 9 Mar 2026 05:58:08 +0000 (01:58 -0400)
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>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
41 files changed:
scripts/rpcgen/tests/test_demo.c
src/admin/libvirt-admin.c
src/hyperv/hyperv_driver.c
src/libvirt.c
src/network/leaseshelper.c
src/qemu/qemu_command.c
src/qemu/qemu_interop_config.c
src/remote/remote_sockets.c
src/rpc/virnetlibsshsession.c
src/rpc/virnettlscontext.c
src/secret/secret_config.c
src/util/virauth.c
src/util/vircommand.c
src/util/virfile.c
src/util/virlease.c
src/util/virlog.c
src/util/virsystemd.c
src/vbox/vbox_XPCOMCGlue.c
src/vbox/vbox_common.c
tests/eventtest.c
tests/fdstreamtest.c
tests/qemucpumock.c
tests/qemusecuritymock.c
tests/securityselinuxhelper.c
tests/testutils.c
tests/testutils.h
tests/testutilsqemu.c
tests/vircgroupmock.c
tests/virfilemock.c
tests/virhostdevtest.c
tests/virmockstathelpers.c
tests/virnetdaemontest.c
tests/virnettlshelpers.c
tests/virpcimock.c
tests/virportallocatormock.c
tests/virscsitest.c
tests/virsystemdtest.c
tests/virtestmock.c
tools/virsh.c
tools/virt-login-shell-helper.c
tools/vsh.c

index 82eda89592f8dfa564b7713685da459804547809..bbf00e88a5a0843e44d30331d206c1f5890d6713 100644 (file)
@@ -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);
     }
 
index d7efac025fc263140919158873f831ddc1f89b35..eebe701fae9416827903dcd0d351c9347f880aad 100644 (file)
@@ -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);
index 906f6e5d198b275abe5e1747201e1a1836137da2..bca65153096f341366a82440edd053f5c32195e0 100644 (file)
@@ -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);
index 375d3fa7ef34a05fc544707e9ae326a6afb86332..b38d21575a4111d110598ed9eb74971f3d69d1f4 100644 (file)
@@ -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);
index 8206712e122b98f33f6b4ac085a1bfd944498002..66a1003785ecf74cfa18347f2ff670c382c9cfe2 100644 (file)
@@ -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);
index ba300f3551e4790d6290da654e9077c19e600e88..d0df7b7826c84dd8471b00cfdb150c2417004786 100644 (file)
@@ -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;
index 2280b8a2dffdc18b81e32b091fabecd778fbedc2..3f7b30f8e05874d4257390145247f6cbb5ae7185 100644 (file)
@@ -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();
index 13b760355b4a9a4f7af5218fa13dda64a3654f3a..b00705cd217806c95ea6dad9b313645d419e4213 100644 (file)
@@ -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;
 
index e496d3334ef5d500b3a9ac7ea80cd5ccfdc93b5f..2f590ec1c4cbaa65e22cf4a0184b4da679bc63cf 100644 (file)
@@ -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);
index dfe793e5db14a9ec544109a0b1d44f946e1df53f..5fed5c71b515c6e873828bc54db738b0263ebf15 100644 (file)
@@ -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;
index 4e11bca1b6b051e9d07ce92be5dcba1d51369219..84514ac5d5581d6aeffb833c17bed60fcca295e6 100644 (file)
@@ -129,7 +129,7 @@ virSecretDaemonConfigNew(bool privileged)
     if (virSecretLoadDaemonConfig(cfg, configfile) < 0)
         return NULL;
 
-    credentialsDirectory = getenv("CREDENTIALS_DIRECTORY");
+    credentialsDirectory = g_getenv("CREDENTIALS_DIRECTORY");
 
     if (!cfg->secretsEncryptionKeyPath && credentialsDirectory) {
         cfg->secretsEncryptionKeyPath = g_strdup_printf("%s/secrets-encryption-key",
index e7a5f7f010f3b2a7f88f590dfb8083c5fa8a1092..fd4b13de7afce095d4f5e3b3b88b6bd4d16fc8a0 100644 (file)
@@ -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;
index 1390c80a3202a73639f27afb76d65307f17f3a17..e871d572a66a94096989a2c401b2197c0328f88c 100644 (file)
@@ -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);
 }
index 65b04beb8cab2ec66b7fc38d348ed758fdd941a2..91d58534812b5d3e0cacb3accb97930421c2ce4e 100644 (file)
@@ -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;
 }
 
index 6fd7b88d88f093ad173c4802518d867c744e791d..a8d53efe5bf26345c67f978c8899ec4f1e12dcc3 100644 (file)
@@ -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;
index 2d262d94f0490b4cf8fad5754e03aa4b4db37324..c24dfa83c4f1da31119be29a46785442713e000e 100644 (file)
@@ -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;
index bd174c683e4b68fd93fbf87b9dd3c95e57553164..faac8b37e3334c50ccb3548aa121e52951d7a96f 100644 (file)
@@ -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"));
index e62549217359290c1fc6af84738e88d6c9dce5e1..a67ceb9a00de840226c68891e54f775da3e5bcdb 100644 (file)
@@ -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) {
index d2a8cf8da4edd993e11e5c35d29d2a800ba49e37..882f9e1f01a4278dc71e943f4cc89ef650fc05e4 100644 (file)
@@ -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)
index 470de4c6304945629daeab888eda3859a9d21bfe..5f78e1fcfec252b92e521a154809df5bfc7b3640 100644 (file)
@@ -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) {
index 5e6b347949c0547b38b0d4bbe3f4c3b95860902a..9d244681f71b67f8880dca72d05eba16c3181ad6 100644 (file)
@@ -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;
index 5a63308347a22b9a4fb954709bb04b455c418e25..c85721f448463ead490f169dad035e0739ca4eac 100644 (file)
@@ -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);
 }
index d5c711b5d77d589cf44678007b999d611fc15fe8..cbd928ab38c8d61b8f4876823b970851930aba22 100644 (file)
@@ -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);
index e5ded964851826b4a2b42bec13d94bc43f0a8ac0..be9d03e815163a012222a6dfb042184658c2d20c 100644 (file)
@@ -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)
index 3c5c298293451bc7fd1cda0a9949373c54c2d0ad..814391b804afd8c9bdeee33785135cc7a6023c1f 100644 (file)
@@ -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;
index e22324e06d214a1d32c04583dc983b0f160877ec..e60876bd9edf3fa3e72fbb3f74bdf6ff31a0d691 100644 (file)
@@ -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; \
index 21dfd3141d1758ebb3d8dc457f70a264fe340a54..d7f2e55330563cac299a244048eb4abcaa61f841 100644 (file)
@@ -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:
index a5c18bd7b05cc57fe31b05456858e120e79daf5a..1aa6f047ce498e0bf14350658986a23cc0b43041 100644 (file)
@@ -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();
 
index 5a09cce85532cfa0979cda46dcfa8c233554afdd..49538dcb71377e4126f33971a3f3fc7947c8dec1 100644 (file)
@@ -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();
 
index a35c1d94026927ecb6eab900632e9ec4b0718bc0..b0fb94e1976801a2504e16b3eae3128e580448a0 100644 (file)
@@ -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);
index 8a76c5e369dead1b674e9183c6069bf1f4d4e4f3..5b1319cedcb077589912d38e42bea301cba4906d 100644 (file)
@@ -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__)
index 1a5c5f32e1f9436259db510890da74a0c35c7909..f2c3ae70edfc88333cd47687f73222253310a6d4 100644 (file)
@@ -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;
index ca293eb6d6f3ec936d180dff55901b507b278471..620068e49565f985cdf4318c7941ae853a30f088 100644 (file)
@@ -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);
 }
 
index ca345f37a3417e930ff2514d1a93922840ec83e4..a5cf0acfc743eaed2cdecc5a7d5a7b90d25bc3a9 100644 (file)
@@ -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);
index 964f4759449184ebb6528e3f0f1d2362478781a6..5fd80c67a0b6bfc8669931b4f08cf20147033679 100644 (file)
@@ -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)) ||
index 2c3b599c7abd0229322e392e6257194cf2bfc782..5cd127807fde5eb45c96c5819469742f02d0e10a 100644 (file)
@@ -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;
index 24c118a4098f073c84759fb6004924fe2e33de54..b93462ae52efe252e00a8e0532fbe041455c1f2e 100644 (file)
@@ -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");
index a5c3b29f39bcf55614c509ab7af8d9e520c14bbf..5610ef46f631472af2c65a034b905f04324a174c 100644 (file)
@@ -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;
     }
index 643ef6b4538c21afa50159dccf5acfb0eee1e233..fdce3220b3fc1d1785edb61af826b8df1c1194c8 100644 (file)
@@ -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);
index a1c68a1afae35d992393dfb939732e360ef4748a..9fe34f55f180d1faa2d444fc6b66b649bcad7a40 100644 (file)
@@ -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)
index 18914cc81864b65c5a251806c12556918a06572d..74016c0043fe90f172957e077302cb139c399303 100644 (file)
@@ -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);