]> xenbits.xensource.com Git - libvirt.git/commitdiff
virGlobalInit: Make glib init its own global state
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 21 Jun 2023 06:56:54 +0000 (08:56 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 22 Jun 2023 08:56:13 +0000 (10:56 +0200)
This should not be needed, but here's what's happening:
virStrToLong_*() family of functions was switched from strtol*()
to g_ascii_strtol*() in order to handle corner cases on Windows
(most notably parsing hex numbers with base=0) - see
v9.4.0-61-g2ed41d7cd9. But what we did not realize back then, is
the fact that g_ascii_strtol*() family has their own global lock
rendering virStrToLong_*() function unsafe between fork() +
exec(). Worse, if one of the threads has to wait for the lock (or
on its corresponding condition), then errno is mangled and
g_ascii_strtol*() signals an error, even though there's no error.

Read more here:

  https://gitlab.gnome.org/GNOME/glib/-/issues/3034

Nevertheless, if we make glib init the g_ascii_strtol*() global
state (by calling one function from g_ascii_strtol*() family),
then there shouldn't be any congestion on the lock and thus no
errno mangling.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/libvirt.c

index 2e470adf98e8b9bba962c577ec1048a6f0896380..69d5b13bff6bf62be6ce59ce9da57855438b2599 100644 (file)
@@ -214,6 +214,14 @@ virGlobalInit(void)
     if (virErrorInitialize() < 0)
         goto error;
 
+    /* Make glib initialize its own global state. See more:
+     *
+     *   https://gitlab.gnome.org/GNOME/glib/-/issues/3034
+     *
+     * TODO: Remove ASAP.
+     */
+    g_ascii_strtoull("0", NULL, 0);
+
     virFileActivateDirOverrideForLib();
 
     if (getuid() != geteuid() ||