summaryrefslogtreecommitdiff
path: root/dbus/dbus-sysdeps-unix.c
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2022-03-01 19:33:06 +0000
committerSimon McVittie <smcv@collabora.com>2022-04-21 11:02:14 +0100
commitee694ade6199932bc9e7ae40f7202c9426599c72 (patch)
treed25cb4df217f8c35d37859bb8855313b05f3b973 /dbus/dbus-sysdeps-unix.c
parentfaa3b2ef4a4807c8a99f8050f733fd82db9f9ce3 (diff)
downloaddbus-ee694ade6199932bc9e7ae40f7202c9426599c72.tar.gz
sysdeps: Use close_range() if available
The version with no flags set, which is a slight generalization of closefrom(), is available on recent Linux and FreeBSD. The version with CLOSE_RANGE_CLOEXEC is Linux-specific. Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'dbus/dbus-sysdeps-unix.c')
-rw-r--r--dbus/dbus-sysdeps-unix.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index 9640e79f..c3dd0b83 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -37,6 +37,7 @@
#include "dbus-credentials.h"
#include "dbus-nonce.h"
+#include <limits.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
@@ -4796,6 +4797,11 @@ act_on_fds_3_and_up (void (*func) (int fd))
void
_dbus_close_all (void)
{
+#ifdef HAVE_CLOSE_RANGE
+ if (close_range (3, INT_MAX, 0) == 0)
+ return;
+#endif
+
/* 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 */
@@ -4818,6 +4824,11 @@ _dbus_close_all (void)
void
_dbus_fd_set_all_close_on_exec (void)
{
+#if defined(HAVE_CLOSE_RANGE) && defined(CLOSE_RANGE_CLOEXEC)
+ if (close_range (3, INT_MAX, CLOSE_RANGE_CLOEXEC) == 0)
+ return;
+#endif
+
act_on_fds_3_and_up (_dbus_fd_set_close_on_exec);
}