Skip to content

Commit 2c33532

Browse files
committed
src: switch to use g_setenv/g_unsetenv
Eliminate direct use of normal setenv/unsetenv calls in favour of GLib's wrapper. This eliminates two gnulib modules Reviewed-by: Fabiano Fidêncio <[email protected]> Signed-off-by: Daniel P. Berrangé <[email protected]>
1 parent 4eed65a commit 2c33532

28 files changed

+87
-87
lines changed

src/security/virt-aa-helper.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1447,11 +1447,11 @@ main(int argc, char **argv)
14471447

14481448
/* clear the environment */
14491449
environ = NULL;
1450-
if (setenv("PATH", "/sbin:/usr/sbin", 1) != 0)
1450+
if (g_setenv("PATH", "/sbin:/usr/sbin", TRUE) == FALSE)
14511451
vah_error(ctl, 1, _("could not set PATH"));
14521452

14531453
/* ensure the traditional IFS setting */
1454-
if (setenv("IFS", " \t\n", 1) != 0)
1454+
if (g_setenv("IFS", " \t\n", TRUE) == FALSE)
14551455
vah_error(ctl, 1, _("could not set IFS"));
14561456

14571457
if (!(progname = strrchr(argv[0], '/')))

src/util/virsystemd.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,8 @@ virSystemdGetListenFDs(void)
854854
return 0;
855855
}
856856

857-
unsetenv("LISTEN_PID");
858-
unsetenv("LISTEN_FDS");
857+
g_unsetenv("LISTEN_PID");
858+
g_unsetenv("LISTEN_FDS");
859859

860860
VIR_DEBUG("Got %u file descriptors", nfds);
861861

src/vbox/vbox_XPCOMCGlue.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing,
104104
*/
105105
if (setAppHome) {
106106
if (dir != NULL) {
107-
setenv("VBOX_APP_HOME", dir, 1 /* always override */);
107+
g_setenv("VBOX_APP_HOME", dir, TRUE);
108108
} else {
109-
unsetenv("VBOX_APP_HOME");
109+
g_unsetenv("VBOX_APP_HOME");
110110
}
111111
}
112112

tests/libxlxml2domconfigtest.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ mymain(void)
160160
* results. In order to detect things that just work by a blind
161161
* chance, we need to set an virtual timezone that no libvirt
162162
* developer resides in. */
163-
if (setenv("TZ", "VIR00:30", 1) < 0) {
164-
perror("setenv");
163+
if (g_setenv("TZ", "VIR00:30", TRUE) == FALSE) {
164+
perror("g_setenv");
165165
return EXIT_FAILURE;
166166
}
167167

tests/lxcxml2xmltest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ mymain(void)
7575
/* Unset or set all envvars here that are copied in lxcdBuildCommandLine
7676
* using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
7777
* values for these envvars */
78-
setenv("PATH", "/bin", 1);
78+
g_setenv("PATH", "/bin", TRUE);
7979

8080
DO_TEST("systemd");
8181
DO_TEST("hostdev");

tests/qemudomaincheckpointxml2xmltest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ mymain(void)
175175
/* Unset or set all envvars here that are copied in qemudBuildCommandLine
176176
* using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
177177
* values for these envvars */
178-
setenv("PATH", "/bin", 1);
178+
g_setenv("PATH", "/bin", TRUE);
179179

180180
/* Test a normal user redefine */
181181
DO_TEST_OUT("redefine", 0);

tests/qemudomainsnapshotxml2xmltest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ mymain(void)
160160
/* Unset or set all envvars here that are copied in qemudBuildCommandLine
161161
* using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
162162
* values for these envvars */
163-
setenv("PATH", "/bin", 1);
163+
g_setenv("PATH", "/bin", TRUE);
164164

165165
DO_TEST_OUT("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
166166
TEST_INTERNAL);

tests/qemufirmwaretest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ testFWPrecedence(const void *opaque G_GNUC_UNUSED)
7070

7171
fakehome = g_strdup(abs_srcdir "/qemufirmwaredata/home/user/.config");
7272

73-
setenv("XDG_CONFIG_HOME", fakehome, 1);
73+
g_setenv("XDG_CONFIG_HOME", fakehome, TRUE);
7474

7575
if (qemuFirmwareFetchConfigs(&fwList, false) < 0)
7676
return -1;

tests/qemuhotplugtest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ mymain(void)
603603
abort();
604604
}
605605

606-
setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
606+
g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
607607

608608
if (qemuTestDriverInit(&driver) < 0)
609609
return EXIT_FAILURE;

tests/qemumemlocktest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ mymain(void)
6767
abort();
6868
}
6969

70-
setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
70+
g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
7171

7272
if (qemuTestDriverInit(&driver) < 0) {
7373
VIR_FREE(fakerootdir);

tests/qemusecuritytest.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ testDomain(const void *opaque)
111111

112112
/* Mocking is enabled only when this env variable is set.
113113
* See mock code for explanation. */
114-
if (setenv(ENVVAR, "1", 0) < 0)
114+
if (g_setenv(ENVVAR, "1", FALSE) == FALSE)
115115
return -1;
116116

117117
if (qemuSecuritySetAllLabel(data->driver, vm, NULL, false) < 0)
@@ -124,7 +124,7 @@ testDomain(const void *opaque)
124124

125125
ret = 0;
126126
cleanup:
127-
unsetenv(ENVVAR);
127+
g_unsetenv(ENVVAR);
128128
freePaths();
129129
return ret;
130130
}

tests/qemuvhostusertest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ testVUPrecedence(const void *opaque G_GNUC_UNUSED)
6868

6969
fakehome = g_strdup(abs_srcdir "/qemuvhostuserdata/home/user/.config");
7070

71-
setenv("XDG_CONFIG_HOME", fakehome, 1);
71+
g_setenv("XDG_CONFIG_HOME", fakehome, TRUE);
7272

7373
if (qemuVhostUserFetchConfigs(&vuList, false) < 0)
7474
return -1;

tests/qemuxml2argvtest.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -618,15 +618,15 @@ mymain(void)
618618
abort();
619619
}
620620

621-
setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
621+
g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
622622

623623
/* Set the timezone because we are mocking the time() function.
624624
* If we don't do that, then localtime() may return unpredictable
625625
* results. In order to detect things that just work by a blind
626626
* chance, we need to set an virtual timezone that no libvirt
627627
* developer resides in. */
628-
if (setenv("TZ", "VIR00:30", 1) < 0) {
629-
perror("setenv");
628+
if (g_setenv("TZ", "VIR00:30", TRUE) == FALSE) {
629+
perror("g_setenv");
630630
return EXIT_FAILURE;
631631
}
632632

@@ -797,15 +797,15 @@ mymain(void)
797797
/* Unset or set all envvars here that are copied in qemudBuildCommandLine
798798
* using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
799799
* values for these envvars */
800-
setenv("PATH", "/bin", 1);
801-
setenv("USER", "test", 1);
802-
setenv("LOGNAME", "test", 1);
803-
setenv("HOME", "/home/test", 1);
804-
unsetenv("TMPDIR");
805-
unsetenv("LD_PRELOAD");
806-
unsetenv("LD_LIBRARY_PATH");
807-
unsetenv("QEMU_AUDIO_DRV");
808-
unsetenv("SDL_AUDIODRIVER");
800+
g_setenv("PATH", "/bin", TRUE);
801+
g_setenv("USER", "test", TRUE);
802+
g_setenv("LOGNAME", "test", TRUE);
803+
g_setenv("HOME", "/home/test", TRUE);
804+
g_unsetenv("TMPDIR");
805+
g_unsetenv("LD_PRELOAD");
806+
g_unsetenv("LD_LIBRARY_PATH");
807+
g_unsetenv("QEMU_AUDIO_DRV");
808+
g_unsetenv("SDL_AUDIODRIVER");
809809

810810
DO_TEST("minimal", NONE);
811811
DO_TEST("minimal-sandbox",

tests/qemuxml2xmltest.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ mymain(void)
147147
abort();
148148
}
149149

150-
setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
150+
g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
151151

152152
/* Required for tpm-emulator tests
153153
*/
@@ -234,7 +234,7 @@ mymain(void)
234234
/* Unset or set all envvars here that are copied in qemudBuildCommandLine
235235
* using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
236236
* values for these envvars */
237-
setenv("PATH", "/bin", 1);
237+
g_setenv("PATH", "/bin", TRUE);
238238

239239
DO_TEST("minimal", NONE);
240240
DO_TEST_CAPS_LATEST("genid");

tests/securityselinuxhelper.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ int setcon_raw(const char *context)
145145
errno = EINVAL;
146146
return -1;
147147
}
148-
return setenv("FAKE_SELINUX_CONTEXT", context, 1);
148+
return g_setenv("FAKE_SELINUX_CONTEXT", context, TRUE);
149149
}
150150

151151
int setcon(const char *context)
@@ -224,7 +224,7 @@ int security_disable(void)
224224
return -1;
225225
}
226226

227-
return setenv("FAKE_SELINUX_DISABLED", "1", 1);
227+
return g_setenv("FAKE_SELINUX_DISABLED", "1", TRUE);
228228
}
229229

230230
int security_getenforce(void)

tests/testutils.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ virTestRun(const char *title,
127127
/* Some test are fragile about environ settings. If that's
128128
* the case, don't poison it. */
129129
if (getenv("VIR_TEST_MOCK_PROGNAME"))
130-
setenv("VIR_TEST_MOCK_TESTNAME", title, 1);
130+
g_setenv("VIR_TEST_MOCK_TESTNAME", title, TRUE);
131131

132132
if (testCounter == 0 && !virTestGetVerbose())
133133
fprintf(stderr, " ");
@@ -176,7 +176,7 @@ virTestRun(const char *title,
176176
fprintf(stderr, "!");
177177
}
178178

179-
unsetenv("VIR_TEST_MOCK_TESTNAME");
179+
g_unsetenv("VIR_TEST_MOCK_TESTNAME");
180180
return ret;
181181
}
182182

@@ -836,7 +836,7 @@ virTestSetEnvPath(void)
836836
}
837837

838838
if (new_path &&
839-
setenv("PATH", new_path, 1) < 0)
839+
g_setenv("PATH", new_path, TRUE) < 0)
840840
goto cleanup;
841841

842842
ret = 0;
@@ -870,7 +870,7 @@ int virTestMain(int argc,
870870
if (STRPREFIX(progname, "lt-"))
871871
progname += 3;
872872

873-
setenv("VIR_TEST_MOCK_PROGNAME", progname, 1);
873+
g_setenv("VIR_TEST_MOCK_PROGNAME", progname, TRUE);
874874

875875
virFileActivateDirOverrideForProg(argv[0]);
876876

tests/testutils.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ int virTestMain(int argc,
121121
#ifdef __APPLE__
122122
# define PRELOAD_VAR "DYLD_INSERT_LIBRARIES"
123123
# define FORCE_FLAT_NAMESPACE \
124-
setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", 1);
124+
g_setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", TRUE);
125125
# define MOCK_EXT ".dylib"
126126
#else
127127
# define PRELOAD_VAR "LD_PRELOAD"
@@ -143,7 +143,7 @@ int virTestMain(int argc,
143143
} else { \
144144
newenv = g_strdup_printf("%s:%s", lib, preload); \
145145
} \
146-
setenv(PRELOAD_VAR, newenv, 1); \
146+
g_setenv(PRELOAD_VAR, newenv, TRUE); \
147147
FORCE_FLAT_NAMESPACE \
148148
execv(argv[0], argv); \
149149
} \

tests/testutilsqemu.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,10 @@ qemuTestSetHostCPU(virQEMUDriverPtr driver,
260260
cpu = cpuPower8;
261261
}
262262

263-
unsetenv("VIR_TEST_MOCK_FAKE_HOST_CPU");
263+
g_unsetenv("VIR_TEST_MOCK_FAKE_HOST_CPU");
264264
if (cpu) {
265265
if (cpu->model)
266-
setenv("VIR_TEST_MOCK_FAKE_HOST_CPU", cpu->model, 1);
266+
g_setenv("VIR_TEST_MOCK_FAKE_HOST_CPU", cpu->model, TRUE);
267267
}
268268
if (driver) {
269269
if (cpu)

tests/vircgrouptest.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ testCgroupDetectMounts(const void *args)
187187
virBuffer buf = VIR_BUFFER_INITIALIZER;
188188
size_t i;
189189

190-
setenv("VIR_CGROUP_MOCK_FILENAME", data->file, 1);
190+
g_setenv("VIR_CGROUP_MOCK_FILENAME", data->file, TRUE);
191191

192192
parsed = g_strdup_printf("%s/vircgroupdata/%s.parsed", abs_srcdir, data->file);
193193

@@ -215,7 +215,7 @@ testCgroupDetectMounts(const void *args)
215215
result = 0;
216216

217217
cleanup:
218-
unsetenv("VIR_CGROUP_MOCK_FILENAME");
218+
g_unsetenv("VIR_CGROUP_MOCK_FILENAME");
219219
VIR_FREE(parsed);
220220
virCgroupFree(&group);
221221
virBufferFreeAndReset(&buf);
@@ -994,13 +994,13 @@ initFakeFS(const char *mode,
994994
abort();
995995
}
996996

997-
setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
997+
g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
998998

999999
if (mode)
1000-
setenv("VIR_CGROUP_MOCK_MODE", mode, 1);
1000+
g_setenv("VIR_CGROUP_MOCK_MODE", mode, TRUE);
10011001

10021002
if (filename)
1003-
setenv("VIR_CGROUP_MOCK_FILENAME", filename, 1);
1003+
g_setenv("VIR_CGROUP_MOCK_FILENAME", filename, TRUE);
10041004

10051005
return fakerootdir;
10061006
}
@@ -1012,9 +1012,9 @@ cleanupFakeFS(char *fakerootdir)
10121012
virFileDeleteTree(fakerootdir);
10131013

10141014
VIR_FREE(fakerootdir);
1015-
unsetenv("LIBVIRT_FAKE_ROOT_DIR");
1016-
unsetenv("VIR_CGROUP_MOCK_MODE");
1017-
unsetenv("VIR_CGROUP_MOCK_FILENAME");
1015+
g_unsetenv("LIBVIRT_FAKE_ROOT_DIR");
1016+
g_unsetenv("VIR_CGROUP_MOCK_MODE");
1017+
g_unsetenv("VIR_CGROUP_MOCK_FILENAME");
10181018
}
10191019

10201020
static int

tests/virfiletest.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED)
327327

328328
mtabFile = g_strdup_printf(abs_srcdir "/virfiledata/%s", data->mtabFile);
329329

330-
if (setenv("LIBVIRT_MTAB", mtabFile, 1) < 0) {
330+
if (g_setenv("LIBVIRT_MTAB", mtabFile, TRUE) == FALSE) {
331331
fprintf(stderr, "Unable to set env variable\n");
332332
goto cleanup;
333333
}
@@ -343,7 +343,7 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED)
343343
ret = 0;
344344
cleanup:
345345
VIR_FREE(mtabFile);
346-
unsetenv("LIBVIRT_MTAB");
346+
g_unsetenv("LIBVIRT_MTAB");
347347
return ret;
348348
#endif
349349
}

tests/virhostdevtest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ mymain(void)
603603
abort();
604604
}
605605

606-
setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
606+
g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
607607

608608
# define DO_TEST(fnc) \
609609
do { \

tests/virnettlscontexttest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mymain(void)
111111
{
112112
int ret = 0;
113113

114-
setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
114+
g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", TRUE);
115115

116116
testTLSInit(KEYFILE);
117117

tests/virnettlssessiontest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ mymain(void)
239239
{
240240
int ret = 0;
241241

242-
setenv("GNUTLS_FORCE_FIPS_MODE", "2", 1);
242+
g_setenv("GNUTLS_FORCE_FIPS_MODE", "2", TRUE);
243243

244244
testTLSInit(KEYFILE);
245245

tests/virpcitest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ mymain(void)
334334
abort();
335335
}
336336

337-
setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
337+
g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
338338

339339
# define DO_TEST(fnc) \
340340
do { \

tests/virportallocatortest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ mymain(void)
171171
if (virTestRun("Test alloc reuse", testAllocReuse, NULL) < 0)
172172
ret = -1;
173173

174-
setenv("LIBVIRT_TEST_IPV4ONLY", "really", 1);
174+
g_setenv("LIBVIRT_TEST_IPV4ONLY", "really", TRUE);
175175

176176
if (virTestRun("Test IPv4-only alloc all", testAllocAll, NULL) < 0)
177177
ret = -1;

0 commit comments

Comments
 (0)