From: Simon McVittie Date: Wed, 2 Mar 2022 12:25:54 +0000 (+0000) Subject: sysdeps: On Linux, wrap close_range syscall directly if necessary X-Git-Tag: dbus-1.15.0~72^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ccea70515eb4a7644c1755b0ba8fd773e9c1871f;p=thirdparty%2Fdbus.git sysdeps: On Linux, wrap close_range syscall directly if necessary This was added to the Linux kernel in version 5.9, but the wrapper wasn't added to glibc until 2.34. Adding our own wrapper for the system call means we can use close_range() on Debian 11 and contemporary distributions. Signed-off-by: Simon McVittie --- diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 735a4fe0f..ce8f4f9d6 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -32,6 +32,7 @@ check_include_file(sys/inotify.h HAVE_SYS_INOTIFY_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) diff --git a/configure.ac b/configure.ac index eed8a7875..26de0a555 100644 --- a/configure.ac +++ b/configure.ac @@ -427,6 +427,7 @@ stdint.h sys/prctl.h sys/random.h sys/resource.h +sys/syscall.h sys/syslimits.h sys/time.h unistd.h diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index ced32063d..9a35d0760 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -84,6 +84,9 @@ #ifdef HAVE_SYS_RANDOM_H #include #endif +#ifdef HAVE_SYS_SYSCALL_H +#include +#endif #ifdef HAVE_ADT #include @@ -141,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.