]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
disable fork-malloc-exec for non-glibc-systems
authorJean-Louis Fuchs <jean-louis.fuchs@adfinis-sygroup.ch>
Mon, 28 Sep 2020 12:45:15 +0000 (14:45 +0200)
committerJean-Louis Fuchs <jean-louis.fuchs@adfinis-sygroup.ch>
Mon, 28 Sep 2020 13:18:12 +0000 (15:18 +0200)
Calling malloc() after fork is undefined behaviour if the process is
multi-threaded. locks held by a thread on fork() will never be released.
malloc() is usally protected by a lock and can therefore deadlock. glibc
is known not to deadlock in this case.

This commit does not rule out other problems on glibc-systems, but fixes an
issue on musl-libc-systems. Only restricting to async-signal safe functions
between fork() and exec() prevents undefined behaviour for sure. See
signal-safety(7).

dbus/dbus-sysdeps-unix.c

index 0288dbc901df42aaa4ab3e85ead843ddcbec1410..e585136f0de714749dbfc63ab4e2b091b641ec9f 100644 (file)
@@ -4742,7 +4742,7 @@ act_on_fds_3_and_up (void (*func) (int fd))
 {
   int maxfds, i;
 
-#ifdef __linux__
+#if defined(__linux__) && defined(__GLIBC__)
   DIR *d;
 
   /* On Linux we can optimize this a bit if /proc is available. If it