From 5f54923c9d24a98a9afb0a46dd1040bd1e3dc833 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 10 Aug 2017 18:52:21 -0700 Subject: [PATCH] Use closefrom() if available in _dbus_close_all() Similar to the #ifdef __linux__ code to use /proc to find open fd's to close, but implemented in libc instead of locally. Available on Solaris, FreeBSD, NetBSD, OpenBSD, and MacOS X. Signed-off-by: Alan Coopersmith --- configure.ac | 2 +- dbus/dbus-sysdeps-unix.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 05182d1f..5c55e63c 100644 --- a/configure.ac +++ b/configure.ac @@ -613,7 +613,7 @@ AC_DEFINE_UNQUOTED([DBUS_USE_SYNC], [$have_sync], [Use the gcc __sync extension] AC_SEARCH_LIBS(socket,[socket network]) AC_CHECK_FUNC(gethostbyname,,[AC_CHECK_LIB(nsl,gethostbyname)]) -AC_CHECK_FUNCS([vsnprintf vasprintf nanosleep usleep setenv clearenv unsetenv socketpair getgrouplist fpathconf setrlimit poll setlocale localeconv strtoll strtoull issetugid getresuid setresuid getrlimit]) +AC_CHECK_FUNCS([vsnprintf vasprintf nanosleep usleep setenv clearenv unsetenv socketpair getgrouplist fpathconf setrlimit poll setlocale localeconv strtoll strtoull issetugid getresuid setresuid getrlimit closefrom]) AC_CHECK_HEADERS([syslog.h]) if test "x$ac_cv_header_syslog_h" = "xyes"; then diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index c1c35f85..b357a2a2 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -4374,6 +4374,9 @@ _dbus_socket_can_pass_unix_fd (DBusSocket fd) void _dbus_close_all (void) { +#ifdef HAVE_CLOSEFROM + closefrom (3); +#else int maxfds, i; #ifdef __linux__ @@ -4430,6 +4433,7 @@ _dbus_close_all (void) /* close all inherited fds */ for (i = 3; i < maxfds; i++) close (i); +#endif /* HAVE_CLOSEFROM */ } /** -- 2.13.0