From: Simon McVittie Date: Tue, 1 Mar 2022 19:12:38 +0000 (+0000) Subject: sysdeps: Only use closefrom() if known to be async-signal-safe X-Git-Tag: dbus-1.15.0~72^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=faa3b2ef4a4807c8a99f8050f733fd82db9f9ce3;p=thirdparty%2Fdbus.git sysdeps: Only use closefrom() if known to be async-signal-safe 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 --- diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 273f3f069..9640e79f1 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -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);