devel/dbus: Pull in a patch that uses closefrom(2)

PR:		240549
This commit is contained in:
Gleb Popov 2024-01-01 22:33:47 +03:00
parent 8482fd8af5
commit 54ceee079e
5 changed files with 137 additions and 12 deletions

View file

@ -1,6 +1,6 @@
PORTNAME= dbus
DISTVERSION= 1.14.10
PORTREVISION= 1
PORTREVISION= 2
PORTEPOCH= 1
CATEGORIES= devel gnome
MASTER_SITES= https://dbus.freedesktop.org/releases/dbus/

View file

@ -1,10 +1,18 @@
--- cmake/ConfigureChecks.cmake.orig 2022-09-14 12:12:21 UTC
--- cmake/ConfigureChecks.cmake.orig 2024-01-01 18:36:58 UTC
+++ cmake/ConfigureChecks.cmake
@@ -51,6 +51,7 @@ check_symbol_exists(clearenv "stdlib.h" HA
check_symbol_exists(setenv "stdlib.h" HAVE_SETENV) # dbus-sysdeps.c
check_symbol_exists(unsetenv "stdlib.h" HAVE_UNSETENV) # dbus-sysdeps.c
check_symbol_exists(clearenv "stdlib.h" HAVE_CLEARENV) # dbus-sysdeps.c
+check_symbol_exists(closefrom "unistd.h" HAVE_CLOSEFROM) # dbus-sysdeps-unix.c
check_symbol_exists(writev "sys/uio.h" HAVE_WRITEV) # dbus-sysdeps.c, dbus-sysdeps-win.c
check_symbol_exists(setrlimit "sys/resource.h" HAVE_SETRLIMIT) # dbus-sysdeps.c, dbus-sysdeps-win.c, test/test-segfault.c
check_symbol_exists(socketpair "sys/socket.h" HAVE_SOCKETPAIR) # dbus-sysdeps.c
@@ -17,6 +17,7 @@ check_include_file(io.h HAVE_IO_H) # inte
check_include_file(grp.h HAVE_GRP_H) # dbus-sysdeps-util-win.c
check_include_file(inttypes.h HAVE_INTTYPES_H) # dbus-pipe.h
check_include_file(io.h HAVE_IO_H) # internal
+check_include_file(linux/close_range.h HAVE_LINUX_CLOSE_RANGE_H)
check_include_file(locale.h HAVE_LOCALE_H)
check_include_file(memory.h HAVE_MEMORY_H)
check_include_file(signal.h HAVE_SIGNAL_H)
@@ -31,6 +32,7 @@ check_include_file(sys/stat.h HAVE_SYS_STAT_H)
check_include_file(sys/random.h HAVE_SYS_RANDOM_H)
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
+check_include_file(sys/syscall.h HAVE_SYS_SYSCALL_H)
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
check_include_file(sys/uio.h HAVE_SYS_UIO_H)
check_include_file(sys/prctl.h HAVE_SYS_PRCTL_H)

View file

@ -1,11 +1,14 @@
--- cmake/config.h.cmake.orig 2022-09-14 12:12:21 UTC
--- cmake/config.h.cmake.orig 2022-10-02 14:06:53 UTC
+++ cmake/config.h.cmake
@@ -198,6 +198,9 @@
@@ -198,6 +198,12 @@
/* Define to 1 if you have clearenv */
#cmakedefine HAVE_CLEARENV 1
+/* Define to 1 if you have closefrom */
+#cmakedefine HAVE_CLOSEFROM 1
+
+/* Define to 1 if you have close_range */
+#cmakedefine HAVE_CLOSE_RANGE 1
+
/* Define to 1 if you have writev */
#cmakedefine HAVE_WRITEV 1

View file

@ -0,0 +1,25 @@
--- configure.orig 2023-09-01 14:31:27 UTC
+++ configure
@@ -3419,6 +3419,8 @@ as_fn_append ac_func_c_list " clearenv HAVE_CLEARENV"
as_fn_append ac_header_c_list " minix/config.h minix_config_h HAVE_MINIX_CONFIG_H"
as_fn_append ac_func_c_list " accept4 HAVE_ACCEPT4"
as_fn_append ac_func_c_list " clearenv HAVE_CLEARENV"
+as_fn_append ac_func_c_list " close_range HAVE_CLOSE_RANGE"
+as_fn_append ac_func_c_list " closefrom HAVE_CLOSEFROM"
as_fn_append ac_func_c_list " fpathconf HAVE_FPATHCONF"
as_fn_append ac_func_c_list " getgrouplist HAVE_GETGROUPLIST"
as_fn_append ac_func_c_list " getpeereid HAVE_GETPEEREID"
@@ -3449,11 +3451,13 @@ as_fn_append ac_header_c_list " errno.h errno_h HAVE_E
as_fn_append ac_header_c_list " crt_externs.h crt_externs_h HAVE_CRT_EXTERNS_H"
as_fn_append ac_header_c_list " dirent.h dirent_h HAVE_DIRENT_H"
as_fn_append ac_header_c_list " errno.h errno_h HAVE_ERRNO_H"
+as_fn_append ac_header_c_list " linux/close_range.h linux_close_range_h HAVE_LINUX_CLOSE_RANGE_H"
as_fn_append ac_header_c_list " locale.h locale_h HAVE_LOCALE_H"
as_fn_append ac_header_c_list " signal.h signal_h HAVE_SIGNAL_H"
as_fn_append ac_header_c_list " sys/prctl.h sys_prctl_h HAVE_SYS_PRCTL_H"
as_fn_append ac_header_c_list " sys/random.h sys_random_h HAVE_SYS_RANDOM_H"
as_fn_append ac_header_c_list " sys/resource.h sys_resource_h HAVE_SYS_RESOURCE_H"
+as_fn_append ac_header_c_list " sys/syscall.h sys_syscall_h HAVE_SYS_SYSCALL_H"
as_fn_append ac_header_c_list " sys/time.h sys_time_h HAVE_SYS_TIME_H"
as_fn_append ac_header_c_list " ws2tcpip.h ws2tcpip_h HAVE_WS2TCPIP_H"
as_fn_append ac_func_c_list " getpwnam_r HAVE_GETPWNAM_R"

View file

@ -0,0 +1,89 @@
--- dbus/dbus-sysdeps-unix.c.orig 2023-08-16 10:29:50 UTC
+++ 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>
@@ -62,6 +63,9 @@
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
+#ifdef HAVE_LINUX_CLOSE_RANGE_H
+#include <linux/close_range.h>
+#endif
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
@@ -80,6 +84,9 @@
#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
#endif
+#ifdef HAVE_SYS_SYSCALL_H
+#include <sys/syscall.h>
+#endif
#ifdef HAVE_ADT
#include <bsm/adt.h>
@@ -137,6 +144,21 @@
#endif /* Solaris */
+#if defined(__linux__) && defined(__NR_close_range) && !defined(HAVE_CLOSE_RANGE)
+/* The kernel headers are new enough to have the close_range syscall,
+ * but glibc isn't new enough to have the syscall wrapper, so call the
+ * syscall directly. */
+static inline int
+close_range (unsigned int first,
+ unsigned int last,
+ unsigned int flags)
+{
+ return syscall (__NR_close_range, first, last, flags);
+}
+/* Now we can call that inline wrapper as though it was provided by glibc. */
+#define HAVE_CLOSE_RANGE
+#endif
+
/**
* Ensure that the standard file descriptors stdin, stdout and stderr
* are open, by opening /dev/null if necessary.
@@ -4791,7 +4813,24 @@ _dbus_close_all (void)
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 */
+#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);
+#endif
}
/**
@@ -4801,6 +4840,11 @@ _dbus_fd_set_all_close_on_exec (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);
}