]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
sysdeps: On Linux, wrap close_range syscall directly if necessary
authorSimon McVittie <smcv@collabora.com>
Wed, 2 Mar 2022 12:25:54 +0000 (12:25 +0000)
committerSimon McVittie <smcv@collabora.com>
Thu, 21 Apr 2022 10:02:44 +0000 (11:02 +0100)
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 <smcv@collabora.com>
cmake/ConfigureChecks.cmake
configure.ac
dbus/dbus-sysdeps-unix.c

index 735a4fe0f837563a78e7ed269eda5c0907ea2bce..ce8f4f9d656592d63b80064aaa9897aaf94f05ec 100644 (file)
@@ -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)
index eed8a7875a08a7aa6af04d9f0bf659e63e5281f1..26de0a555ad99efbf8fe5c353ceef26c291798a7 100644 (file)
@@ -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
index ced32063dee8f91ade2959741cd95b2305f6c3fe..9a35d07600422916d41689fc39fbdd9fde60485d 100644 (file)
@@ -84,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>
 
 #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.