]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuNamespaceMknodOne: Call g_file_read_link() in async-signal-safe fashion
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 28 Sep 2022 07:53:47 +0000 (09:53 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 30 Sep 2022 08:09:32 +0000 (10:09 +0200)
When creating a node in QEMU's namespace the whole link chain is
created with it. Here, we use g_file_read_link() from the child
(running inside the namespace) to learn whether a link exists and
points to expected target. Now, when building the namespace there
can't be any symlinks and this g_file_read_link() returns NULL
always. And because we pass a local GError variable to it, glib
tries to set it to a localized error message. This comes with
creating a (static) hash table inside of g_strerror() and is
guarded with a mutex. The hash table is also allocated using
GSlice allocator instead of g_malloc, and since the latter is
safe to use after fork (because it's documented to use plain
malloc), glib went with the former, naturally. Now, GSlice
allocator has plenty of internal mutexes and thus hitting a
locked mutex is not that hard.

Fortunately, we don't care about any error from
g_file_read_link() and thus we can pass NULL which avoids calling
g_strerror().

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2120965
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
src/qemu/qemu_namespace.c

index a2c31310d97cddb700b1882ab16826b253a4340d..311c66d46eee2df8892efe738c6649a0882a4200 100644 (file)
@@ -957,10 +957,9 @@ qemuNamespaceMknodOne(qemuNamespaceMknodItem *data)
     }
 
     if (isLink) {
-        g_autoptr(GError) gerr = NULL;
         g_autofree char *target = NULL;
 
-        if ((target = g_file_read_link(data->file, &gerr)) &&
+        if ((target = g_file_read_link(data->file, NULL)) &&
             STREQ(target, data->target)) {
             VIR_DEBUG("Skipping symlink %s -> %s which exists and points to correct target",
                       data->file, data->target);