]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
sysdeps: Only use closefrom() if known to be async-signal-safe
authorSimon McVittie <smcv@collabora.com>
Tue, 1 Mar 2022 19:12:38 +0000 (19:12 +0000)
committerSimon McVittie <smcv@collabora.com>
Thu, 21 Apr 2022 10:02:14 +0000 (11:02 +0100)
closefrom() is known to be async-signal-safe on FreeBSD, NetBSD and
OpenBSD, and safe to call after fork() on Solaris, but not necessarily
on DragonflyBSD.

Signed-off-by: Simon McVittie <smcv@collabora.com>
dbus/dbus-sysdeps-unix.c

index 273f3f069e5e810da105484eff368a47409094b4..9640e79f10520923720a3d9dd463faebf8540b17 100644 (file)
@@ -4796,7 +4796,15 @@ act_on_fds_3_and_up (void (*func) (int fd))
 void
 _dbus_close_all (void)
 {
-#ifdef HAVE_CLOSEFROM
+  /* Some library implementations of closefrom() are not async-signal-safe,
+   * and we call _dbus_close_all() after forking, so we only do this on
+   * operating systems where we know that closefrom() is a system call */
+#if defined(HAVE_CLOSEFROM) && ( \
+    defined(__FreeBSD__) || \
+    defined(__NetBSD__) || \
+    defined(__OpenBSD__) || \
+    defined(__sun__) && defined(F_CLOSEFROM) \
+)
   closefrom (3);
 #else
   act_on_fds_3_and_up (close_ignore_error);