Eliminate direct use of normal setenv/unsetenv calls in favour of GLib's wrapper. This eliminates two gnulib modules Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> --- src/security/virt-aa-helper.c | 4 +-- src/util/virsystemd.c | 4 +-- src/vbox/vbox_XPCOMCGlue.c | 4 +-- tests/libxlxml2domconfigtest.c | 4 +-- tests/lxcxml2xmltest.c | 2 +- tests/qemudomaincheckpointxml2xmltest.c | 2 +- tests/qemudomainsnapshotxml2xmltest.c | 2 +- tests/qemufirmwaretest.c | 2 +- tests/qemuhotplugtest.c | 2 +- tests/qemumemlocktest.c | 2 +- tests/qemusecuritytest.c | 4 +-- tests/qemuvhostusertest.c | 2 +- tests/qemuxml2argvtest.c | 24 ++++++------- tests/qemuxml2xmltest.c | 4 +-- tests/securityselinuxhelper.c | 4 +-- tests/testutils.c | 8 ++--- tests/testutils.h | 4 +-- tests/testutilsqemu.c | 4 +-- tests/vircgrouptest.c | 16 ++++----- tests/virfiletest.c | 4 +-- tests/virhostdevtest.c | 2 +- tests/virnettlscontexttest.c | 2 +- tests/virnettlssessiontest.c | 2 +- tests/virpcitest.c | 2 +- tests/virportallocatortest.c | 2 +- tests/virsystemdtest.c | 46 ++++++++++++------------- tests/virtimetest.c | 4 +-- tools/virt-login-shell-helper.c | 12 +++---- 28 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index f623ff965f..feb03b0aa9 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1447,11 +1447,11 @@ main(int argc, char **argv) /* clear the environment */ environ = NULL; - if (setenv("PATH", "/sbin:/usr/sbin", 1) != 0) + if (g_setenv("PATH", "/sbin:/usr/sbin", 1) == FALSE) vah_error(ctl, 1, _("could not set PATH")); /* ensure the traditional IFS setting */ - if (setenv("IFS", " \t\n", 1) != 0) + if (g_setenv("IFS", " \t\n", 1) == FALSE) vah_error(ctl, 1, _("could not set IFS")); if (!(progname = strrchr(argv[0], '/'))) diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 2acb54d41e..96d43e5440 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -854,8 +854,8 @@ virSystemdGetListenFDs(void) return 0; } - unsetenv("LISTEN_PID"); - unsetenv("LISTEN_FDS"); + g_unsetenv("LISTEN_PID"); + g_unsetenv("LISTEN_FDS"); VIR_DEBUG("Got %u file descriptors", nfds); diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c index f48a78a923..4151d20909 100644 --- a/src/vbox/vbox_XPCOMCGlue.c +++ b/src/vbox/vbox_XPCOMCGlue.c @@ -104,9 +104,9 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing, */ if (setAppHome) { if (dir != NULL) { - setenv("VBOX_APP_HOME", dir, 1 /* always override */); + g_setenv("VBOX_APP_HOME", dir, 1 /* always override */); } else { - unsetenv("VBOX_APP_HOME"); + g_unsetenv("VBOX_APP_HOME"); } } diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c index 35f0ce8f7d..f3b8c8bffd 100644 --- a/tests/libxlxml2domconfigtest.c +++ b/tests/libxlxml2domconfigtest.c @@ -160,8 +160,8 @@ mymain(void) * results. In order to detect things that just work by a blind * chance, we need to set an virtual timezone that no libvirt * developer resides in. */ - if (setenv("TZ", "VIR00:30", 1) < 0) { - perror("setenv"); + if (g_setenv("TZ", "VIR00:30", 1) == FALSE) { + perror("g_setenv"); return EXIT_FAILURE; } diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index 7b05f7d016..f7457e719a 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -75,7 +75,7 @@ mymain(void) /* Unset or set all envvars here that are copied in lxcdBuildCommandLine * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected * values for these envvars */ - setenv("PATH", "/bin", 1); + g_setenv("PATH", "/bin", 1); DO_TEST("systemd"); DO_TEST("hostdev"); diff --git a/tests/qemudomaincheckpointxml2xmltest.c b/tests/qemudomaincheckpointxml2xmltest.c index 4d6904a592..b27c0e362a 100644 --- a/tests/qemudomaincheckpointxml2xmltest.c +++ b/tests/qemudomaincheckpointxml2xmltest.c @@ -175,7 +175,7 @@ mymain(void) /* Unset or set all envvars here that are copied in qemudBuildCommandLine * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected * values for these envvars */ - setenv("PATH", "/bin", 1); + g_setenv("PATH", "/bin", 1); /* Test a normal user redefine */ DO_TEST_OUT("redefine", 0); diff --git a/tests/qemudomainsnapshotxml2xmltest.c b/tests/qemudomainsnapshotxml2xmltest.c index 6bff5d14f5..ebdfea7eca 100644 --- a/tests/qemudomainsnapshotxml2xmltest.c +++ b/tests/qemudomainsnapshotxml2xmltest.c @@ -160,7 +160,7 @@ mymain(void) /* Unset or set all envvars here that are copied in qemudBuildCommandLine * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected * values for these envvars */ - setenv("PATH", "/bin", 1); + g_setenv("PATH", "/bin", 1); DO_TEST_OUT("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", TEST_INTERNAL); diff --git a/tests/qemufirmwaretest.c b/tests/qemufirmwaretest.c index 906d594ace..dffe47c386 100644 --- a/tests/qemufirmwaretest.c +++ b/tests/qemufirmwaretest.c @@ -70,7 +70,7 @@ testFWPrecedence(const void *opaque G_GNUC_UNUSED) fakehome = g_strdup(abs_srcdir "/qemufirmwaredata/home/user/.config"); - setenv("XDG_CONFIG_HOME", fakehome, 1); + g_setenv("XDG_CONFIG_HOME", fakehome, 1); if (qemuFirmwareFetchConfigs(&fwList, false) < 0) return -1; diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 6ab2d9b0f4..e7fe8da0b7 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -603,7 +603,7 @@ mymain(void) abort(); } - setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); + g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); if (qemuTestDriverInit(&driver) < 0) return EXIT_FAILURE; diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c index 7de0d72410..455306b0c2 100644 --- a/tests/qemumemlocktest.c +++ b/tests/qemumemlocktest.c @@ -67,7 +67,7 @@ mymain(void) abort(); } - setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); + g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); if (qemuTestDriverInit(&driver) < 0) { VIR_FREE(fakerootdir); diff --git a/tests/qemusecuritytest.c b/tests/qemusecuritytest.c index 380c3fed8c..bf34eb2f71 100644 --- a/tests/qemusecuritytest.c +++ b/tests/qemusecuritytest.c @@ -111,7 +111,7 @@ testDomain(const void *opaque) /* Mocking is enabled only when this env variable is set. * See mock code for explanation. */ - if (setenv(ENVVAR, "1", 0) < 0) + if (g_setenv(ENVVAR, "1", 0) == FALSE) return -1; if (qemuSecuritySetAllLabel(data->driver, vm, NULL, false) < 0) @@ -124,7 +124,7 @@ testDomain(const void *opaque) ret = 0; cleanup: - unsetenv(ENVVAR); + g_unsetenv(ENVVAR); freePaths(); return ret; } diff --git a/tests/qemuvhostusertest.c b/tests/qemuvhostusertest.c index cc1e523841..6ff7923099 100644 --- a/tests/qemuvhostusertest.c +++ b/tests/qemuvhostusertest.c @@ -68,7 +68,7 @@ testVUPrecedence(const void *opaque G_GNUC_UNUSED) fakehome = g_strdup(abs_srcdir "/qemuvhostuserdata/home/user/.config"); - setenv("XDG_CONFIG_HOME", fakehome, 1); + g_setenv("XDG_CONFIG_HOME", fakehome, 1); if (qemuVhostUserFetchConfigs(&vuList, false) < 0) return -1; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index bfbed5c31d..cc34d0caee 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -618,15 +618,15 @@ mymain(void) abort(); } - setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); + g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); /* Set the timezone because we are mocking the time() function. * If we don't do that, then localtime() may return unpredictable * results. In order to detect things that just work by a blind * chance, we need to set an virtual timezone that no libvirt * developer resides in. */ - if (setenv("TZ", "VIR00:30", 1) < 0) { - perror("setenv"); + if (g_setenv("TZ", "VIR00:30", 1) == FALSE) { + perror("g_setenv"); return EXIT_FAILURE; } @@ -797,15 +797,15 @@ mymain(void) /* Unset or set all envvars here that are copied in qemudBuildCommandLine * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected * values for these envvars */ - setenv("PATH", "/bin", 1); - setenv("USER", "test", 1); - setenv("LOGNAME", "test", 1); - setenv("HOME", "/home/test", 1); - unsetenv("TMPDIR"); - unsetenv("LD_PRELOAD"); - unsetenv("LD_LIBRARY_PATH"); - unsetenv("QEMU_AUDIO_DRV"); - unsetenv("SDL_AUDIODRIVER"); + g_setenv("PATH", "/bin", 1); + g_setenv("USER", "test", 1); + g_setenv("LOGNAME", "test", 1); + g_setenv("HOME", "/home/test", 1); + g_unsetenv("TMPDIR"); + g_unsetenv("LD_PRELOAD"); + g_unsetenv("LD_LIBRARY_PATH"); + g_unsetenv("QEMU_AUDIO_DRV"); + g_unsetenv("SDL_AUDIODRIVER"); DO_TEST("minimal", NONE); DO_TEST("minimal-sandbox", diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 34c2ec8c5f..6463cf81e2 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -147,7 +147,7 @@ mymain(void) abort(); } - setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); + g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); /* Required for tpm-emulator tests */ @@ -234,7 +234,7 @@ mymain(void) /* Unset or set all envvars here that are copied in qemudBuildCommandLine * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected * values for these envvars */ - setenv("PATH", "/bin", 1); + g_setenv("PATH", "/bin", 1); DO_TEST("minimal", NONE); DO_TEST_CAPS_LATEST("genid"); diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c index 8b90ddada9..50d4f40dc5 100644 --- a/tests/securityselinuxhelper.c +++ b/tests/securityselinuxhelper.c @@ -145,7 +145,7 @@ int setcon_raw(const char *context) errno = EINVAL; return -1; } - return setenv("FAKE_SELINUX_CONTEXT", context, 1); + return g_setenv("FAKE_SELINUX_CONTEXT", context, 1); } int setcon(const char *context) @@ -224,7 +224,7 @@ int security_disable(void) return -1; } - return setenv("FAKE_SELINUX_DISABLED", "1", 1); + return g_setenv("FAKE_SELINUX_DISABLED", "1", 1); } int security_getenforce(void) diff --git a/tests/testutils.c b/tests/testutils.c index 6efc877d0c..5bc108a6c3 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -127,7 +127,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")) - setenv("VIR_TEST_MOCK_TESTNAME", title, 1); + g_setenv("VIR_TEST_MOCK_TESTNAME", title, 1); if (testCounter == 0 && !virTestGetVerbose()) fprintf(stderr, " "); @@ -176,7 +176,7 @@ virTestRun(const char *title, fprintf(stderr, "!"); } - unsetenv("VIR_TEST_MOCK_TESTNAME"); + g_unsetenv("VIR_TEST_MOCK_TESTNAME"); return ret; } @@ -836,7 +836,7 @@ virTestSetEnvPath(void) } if (new_path && - setenv("PATH", new_path, 1) < 0) + g_setenv("PATH", new_path, 1) < 0) goto cleanup; ret = 0; @@ -870,7 +870,7 @@ int virTestMain(int argc, if (STRPREFIX(progname, "lt-")) progname += 3; - setenv("VIR_TEST_MOCK_PROGNAME", progname, 1); + g_setenv("VIR_TEST_MOCK_PROGNAME", progname, 1); virFileActivateDirOverrideForProg(argv[0]); diff --git a/tests/testutils.h b/tests/testutils.h index dcb7cc4c04..74785b7fb8 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -121,7 +121,7 @@ int virTestMain(int argc, #ifdef __APPLE__ # define PRELOAD_VAR "DYLD_INSERT_LIBRARIES" # define FORCE_FLAT_NAMESPACE \ - setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", 1); + g_setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", 1); # define MOCK_EXT ".dylib" #else # define PRELOAD_VAR "LD_PRELOAD" @@ -143,7 +143,7 @@ int virTestMain(int argc, } else { \ newenv = g_strdup_printf("%s:%s", lib, preload); \ } \ - setenv(PRELOAD_VAR, newenv, 1); \ + g_setenv(PRELOAD_VAR, newenv, 1); \ FORCE_FLAT_NAMESPACE \ execv(argv[0], argv); \ } \ diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index d077f8cd2d..4ca72446da 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -260,10 +260,10 @@ qemuTestSetHostCPU(virQEMUDriverPtr driver, cpu = cpuPower8; } - unsetenv("VIR_TEST_MOCK_FAKE_HOST_CPU"); + g_unsetenv("VIR_TEST_MOCK_FAKE_HOST_CPU"); if (cpu) { if (cpu->model) - setenv("VIR_TEST_MOCK_FAKE_HOST_CPU", cpu->model, 1); + g_setenv("VIR_TEST_MOCK_FAKE_HOST_CPU", cpu->model, 1); } if (driver) { if (cpu) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 5e9f619a84..cde07518ef 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -187,7 +187,7 @@ testCgroupDetectMounts(const void *args) virBuffer buf = VIR_BUFFER_INITIALIZER; size_t i; - setenv("VIR_CGROUP_MOCK_FILENAME", data->file, 1); + g_setenv("VIR_CGROUP_MOCK_FILENAME", data->file, 1); parsed = g_strdup_printf("%s/vircgroupdata/%s.parsed", abs_srcdir, data->file); @@ -215,7 +215,7 @@ testCgroupDetectMounts(const void *args) result = 0; cleanup: - unsetenv("VIR_CGROUP_MOCK_FILENAME"); + g_unsetenv("VIR_CGROUP_MOCK_FILENAME"); VIR_FREE(parsed); virCgroupFree(&group); virBufferFreeAndReset(&buf); @@ -994,13 +994,13 @@ initFakeFS(const char *mode, abort(); } - setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); + g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); if (mode) - setenv("VIR_CGROUP_MOCK_MODE", mode, 1); + g_setenv("VIR_CGROUP_MOCK_MODE", mode, 1); if (filename) - setenv("VIR_CGROUP_MOCK_FILENAME", filename, 1); + g_setenv("VIR_CGROUP_MOCK_FILENAME", filename, 1); return fakerootdir; } @@ -1012,9 +1012,9 @@ cleanupFakeFS(char *fakerootdir) virFileDeleteTree(fakerootdir); VIR_FREE(fakerootdir); - unsetenv("LIBVIRT_FAKE_ROOT_DIR"); - unsetenv("VIR_CGROUP_MOCK_MODE"); - unsetenv("VIR_CGROUP_MOCK_FILENAME"); + g_unsetenv("LIBVIRT_FAKE_ROOT_DIR"); + g_unsetenv("VIR_CGROUP_MOCK_MODE"); + g_unsetenv("VIR_CGROUP_MOCK_FILENAME"); } static int diff --git a/tests/virfiletest.c b/tests/virfiletest.c index 781c640e2b..4d69df5b56 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -327,7 +327,7 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED) mtabFile = g_strdup_printf(abs_srcdir "/virfiledata/%s", data->mtabFile); - if (setenv("LIBVIRT_MTAB", mtabFile, 1) < 0) { + if (g_setenv("LIBVIRT_MTAB", mtabFile, 1) == FALSE) { fprintf(stderr, "Unable to set env variable\n"); goto cleanup; } @@ -343,7 +343,7 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED) ret = 0; cleanup: VIR_FREE(mtabFile); - unsetenv("LIBVIRT_MTAB"); + g_unsetenv("LIBVIRT_MTAB"); return ret; #endif } diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index ffd7ce1aab..1c648f466a 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -603,7 +603,7 @@ mymain(void) abort(); } - setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); + g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); # define DO_TEST(fnc) \ do { \ diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c index 6c01336420..2210c8cc91 100644 --- a/tests/virnettlscontexttest.c +++ b/tests/virnettlscontexttest.c @@ -111,7 +111,7 @@ mymain(void) { int ret = 0; - setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1); + g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1); testTLSInit(KEYFILE); diff --git a/tests/virnettlssessiontest.c b/tests/virnettlssessiontest.c index 997cf5a372..59924c7037 100644 --- a/tests/virnettlssessiontest.c +++ b/tests/virnettlssessiontest.c @@ -239,7 +239,7 @@ mymain(void) { int ret = 0; - setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1); + g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1); testTLSInit(KEYFILE); diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 68fe9c8345..922f241d54 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -334,7 +334,7 @@ mymain(void) abort(); } - setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); + g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1); # define DO_TEST(fnc) \ do { \ diff --git a/tests/virportallocatortest.c b/tests/virportallocatortest.c index 8e62fc4519..4e50cd74b3 100644 --- a/tests/virportallocatortest.c +++ b/tests/virportallocatortest.c @@ -171,7 +171,7 @@ mymain(void) if (virTestRun("Test alloc reuse", testAllocReuse, NULL) < 0) ret = -1; - setenv("LIBVIRT_TEST_IPV4ONLY", "really", 1); + g_setenv("LIBVIRT_TEST_IPV4ONLY", "really", 1); if (virTestRun("Test IPv4-only alloc all", testAllocAll, NULL) < 0) ret = -1; diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index b5624241bb..583d7efd65 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -236,7 +236,7 @@ static int testCreateNoSystemd(const void *opaque G_GNUC_UNUSED) }; int rv; - setenv("FAIL_NO_SERVICE", "1", 1); + g_setenv("FAIL_NO_SERVICE", "1", 1); if ((rv = virSystemdCreateMachine("demo", "qemu", @@ -246,11 +246,11 @@ static int testCreateNoSystemd(const void *opaque G_GNUC_UNUSED) false, 0, NULL, NULL, 0)) == 0) { - unsetenv("FAIL_NO_SERVICE"); + g_unsetenv("FAIL_NO_SERVICE"); fprintf(stderr, "%s", "Unexpected create machine success\n"); return -1; } - unsetenv("FAIL_NO_SERVICE"); + g_unsetenv("FAIL_NO_SERVICE"); if (rv != -2) { fprintf(stderr, "%s", "Unexpected create machine error\n"); @@ -270,7 +270,7 @@ static int testCreateSystemdNotRunning(const void *opaque G_GNUC_UNUSED) }; int rv; - setenv("FAIL_NOT_REGISTERED", "1", 1); + g_setenv("FAIL_NOT_REGISTERED", "1", 1); if ((rv = virSystemdCreateMachine("demo", "qemu", @@ -280,11 +280,11 @@ static int testCreateSystemdNotRunning(const void *opaque G_GNUC_UNUSED) false, 0, NULL, NULL, 0)) == 0) { - unsetenv("FAIL_NOT_REGISTERED"); + g_unsetenv("FAIL_NOT_REGISTERED"); fprintf(stderr, "%s", "Unexpected create machine success\n"); return -1; } - unsetenv("FAIL_NOT_REGISTERED"); + g_unsetenv("FAIL_NOT_REGISTERED"); if (rv != -2) { fprintf(stderr, "%s", "Unexpected create machine error\n"); @@ -304,7 +304,7 @@ static int testCreateBadSystemd(const void *opaque G_GNUC_UNUSED) }; int rv; - setenv("FAIL_BAD_SERVICE", "1", 1); + g_setenv("FAIL_BAD_SERVICE", "1", 1); if ((rv = virSystemdCreateMachine("demo", "qemu", @@ -314,11 +314,11 @@ static int testCreateBadSystemd(const void *opaque G_GNUC_UNUSED) false, 0, NULL, NULL, 0)) == 0) { - unsetenv("FAIL_BAD_SERVICE"); + g_unsetenv("FAIL_BAD_SERVICE"); fprintf(stderr, "%s", "Unexpected create machine success\n"); return -1; } - unsetenv("FAIL_BAD_SERVICE"); + g_unsetenv("FAIL_BAD_SERVICE"); if (rv != -1) { fprintf(stderr, "%s", "Unexpected create machine error\n"); @@ -445,7 +445,7 @@ static int testPMSupportHelper(const void *opaque) const struct testPMSupportData *data = opaque; for (i = 0; i < 4; i++) { - setenv("RESULT_SUPPORT", results[i], 1); + g_setenv("RESULT_SUPPORT", results[i], 1); if ((rv = data->tested(&result)) < 0) { fprintf(stderr, "%s", "Unexpected canSuspend error\n"); return -1; @@ -455,12 +455,12 @@ static int testPMSupportHelper(const void *opaque) fprintf(stderr, "Unexpected result for answer '%s'\n", results[i]); goto error; } - unsetenv("RESULT_SUPPORT"); + g_unsetenv("RESULT_SUPPORT"); } return 0; error: - unsetenv("RESULT_SUPPORT"); + g_unsetenv("RESULT_SUPPORT"); return -1; } @@ -470,14 +470,14 @@ static int testPMSupportHelperNoSystemd(const void *opaque) bool result; const struct testPMSupportData *data = opaque; - setenv("FAIL_NO_SERVICE", "1", 1); + g_setenv("FAIL_NO_SERVICE", "1", 1); if ((rv = data->tested(&result)) == 0) { - unsetenv("FAIL_NO_SERVICE"); + g_unsetenv("FAIL_NO_SERVICE"); fprintf(stderr, "%s", "Unexpected canSuspend success\n"); return -1; } - unsetenv("FAIL_NO_SERVICE"); + g_unsetenv("FAIL_NO_SERVICE"); if (rv != -2) { fprintf(stderr, "%s", "Unexpected canSuspend error\n"); @@ -493,14 +493,14 @@ static int testPMSupportSystemdNotRunning(const void *opaque) bool result; const struct testPMSupportData *data = opaque; - setenv("FAIL_NOT_REGISTERED", "1", 1); + g_setenv("FAIL_NOT_REGISTERED", "1", 1); if ((rv = data->tested(&result)) == 0) { - unsetenv("FAIL_NOT_REGISTERED"); + g_unsetenv("FAIL_NOT_REGISTERED"); fprintf(stderr, "%s", "Unexpected canSuspend success\n"); return -1; } - unsetenv("FAIL_NOT_REGISTERED"); + g_unsetenv("FAIL_NOT_REGISTERED"); if (rv != -2) { fprintf(stderr, "%s", "Unexpected canSuspend error\n"); @@ -567,13 +567,13 @@ testActivation(bool useNames) g_snprintf(nfdstr, sizeof(nfdstr), "%zu", 1 + nsockIP); g_snprintf(pidstr, sizeof(pidstr), "%lld", (long long)getpid()); - setenv("LISTEN_FDS", nfdstr, 1); - setenv("LISTEN_PID", pidstr, 1); + g_setenv("LISTEN_FDS", nfdstr, 1); + g_setenv("LISTEN_PID", pidstr, 1); if (useNames) - setenv("LISTEN_FDNAMES", virBufferCurrentContent(&names), 1); + g_setenv("LISTEN_FDNAMES", virBufferCurrentContent(&names), 1); else - unsetenv("LISTEN_FDNAMES"); + g_unsetenv("LISTEN_FDNAMES"); map[0].name = "demo-unix.socket"; map[0].family = AF_UNIX; @@ -640,7 +640,7 @@ testActivationEmpty(const void *opaque G_GNUC_UNUSED) { virSystemdActivationPtr act; - unsetenv("LISTEN_FDS"); + g_unsetenv("LISTEN_FDS"); if (virSystemdGetActivation(NULL, 0, &act) < 0) return -1; diff --git a/tests/virtimetest.c b/tests/virtimetest.c index 1eb321858b..4860bf758f 100644 --- a/tests/virtimetest.c +++ b/tests/virtimetest.c @@ -79,8 +79,8 @@ testTimeLocalOffset(const void *args) const testTimeLocalOffsetData *data = args; long actual; - if (setenv("TZ", data->zone, 1) < 0) { - perror("setenv"); + if (g_setenv("TZ", data->zone, 1) == FALSE) { + perror("g_setenv"); return -1; } tzset(); diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helper.c index ace8733968..87735833d9 100644 --- a/tools/virt-login-shell-helper.c +++ b/tools/virt-login-shell-helper.c @@ -382,13 +382,13 @@ main(int argc, char **argv) } clearenv(); - setenv("PATH", "/bin:/usr/bin", 1); - setenv("SHELL", shcmd, 1); - setenv("USER", name, 1); - setenv("LOGNAME", name, 1); - setenv("HOME", homedir, 1); + g_setenv("PATH", "/bin:/usr/bin", 1); + g_setenv("SHELL", shcmd, 1); + g_setenv("USER", name, 1); + g_setenv("LOGNAME", name, 1); + g_setenv("HOME", homedir, 1); if (term) - setenv("TERM", term, 1); + g_setenv("TERM", term, 1); if (execv(shcmd, (char *const*) shargv) < 0) { virReportSystemError(errno, _("Unable to exec shell %s"), -- 2.24.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list