mirror of
https://github.com/libvirt/libvirt.git
synced 2026-08-19 01:24:42 -05:00
consistently use glib g_getenv() instead of libc getenv()
We've been using glib g_setenv() since commit
2c33532423 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>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user