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