]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: Check for errors in virLogSetFromEnv
authorMartin Kletzander <mkletzan@redhat.com>
Wed, 15 Dec 2021 15:34:16 +0000 (16:34 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 5 Jan 2022 13:08:40 +0000 (14:08 +0100)
commit9f6749dea0e3638bfea2b4e429b7dbba200331f3
treef62cbbae9079c50292623457e256e24e3f60b65d
parenta873924e36b28c5b125621e35b32beb6b077bcc8
util: Check for errors in virLogSetFromEnv

And make callers check the return value as well.  This helps error out early for
invalid environment variables.

That is desirable because it could lead to deadlocks.  This can happen when
resetting logging after fork() reports translated errors because gettext
functions are not reentrant.  Well, it is not limited to resetting logging after
fork(), it can be any translation at that phase, but parsing environment
variables is easy to make fail on purpose to show the result, it can also happen
just due to a typo.

Before this commit it is possible to deadlock the daemon on startup
with something like:

LIBVIRT_LOG_FILTERS='1:*' LIBVIRT_LOG_OUTPUTS=1:stdout libvirtd

where filters are used to enable more logging and hence make the race less rare
and outputs are set to invalid

Combined with the previous patches this changes
the following from:

...
<deadlock>

to:

...
libvirtd: initialisation failed

The error message is improved in future commits and is also possible thanks to
this patch.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/admin/libvirt-admin.c
src/libvirt.c
src/lxc/lxc_controller.c
src/remote/remote_ssh_helper.c
src/security/virt-aa-helper.c
src/util/vircommand.c
src/util/virdaemon.c
src/util/virlog.c
src/util/virlog.h
tests/testutils.c