]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
syscalls: add close_range()
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 3 Feb 2021 08:45:30 +0000 (09:45 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 3 Feb 2021 08:45:30 +0000 (09:45 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
configure.ac
src/lxc/syscall_numbers.h
src/lxc/syscall_wrappers.h

index 4f31d94ac8cfe9a2ae82ddad086864a10c12c5f1..60d7a91e6b1070d630ae1c34962817380896e260 100644 (file)
@@ -644,7 +644,7 @@ AC_CHECK_HEADER([ifaddrs.h],
 AC_HEADER_MAJOR
 
 # Check for some syscalls functions
-AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r confstr faccessat gettid memfd_create move_mount open_tree execveat clone3 fsopen fspick fsconfig fsmount, openat2])
+AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r confstr faccessat gettid memfd_create move_mount open_tree execveat clone3 fsopen fspick fsconfig fsmount, openat2, close_range])
 AC_CHECK_TYPES([struct open_how], [], [], [[#include <linux/openat2.h>]])
 AC_CHECK_TYPES([struct clone_args], [], [], [[#include <linux/sched.h>]])
 AC_CHECK_MEMBERS([struct clone_args.set_tid],[],[],[[#include <linux/sched.h>]])
index 8305173d6be670d6b447961bcb3913e90f1c7485..0bc5efe3d8d234de2525eea342b0be8ec740486d 100644 (file)
        #endif
 #endif
 
+#ifndef __NR_close_range
+       #if defined __alpha__
+               #define __NR_close_range 546
+       #elif defined _MIPS_SIM
+               #if _MIPS_SIM == _MIPS_SIM_ABI32        /* o32 */
+                       #define __NR_close_range (436 + 4000)
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_NABI32       /* n32 */
+                       #define __NR_close_range (436 + 6000)
+               #endif
+               #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
+                       #define __NR_close_range (436 + 5000)
+               #endif
+       #elif defined __ia64__
+               #define __NR_close_range (436 + 1024)
+       #else
+               #define __NR_close_range 436
+       #endif
+#endif
+
 #endif /* __LXC_SYSCALL_NUMBERS_H */
index de931a3511f2af36db99cd1c98d6bb39e2a59c5f..757f370f83c84a13e43225d6c1f9ac676cbaea2a 100644 (file)
@@ -282,4 +282,19 @@ static inline int openat2(int dfd, const char *filename, struct lxc_open_how *ho
 }
 #endif /* HAVE_OPENAT2 */
 
+#ifndef CLOSE_RANGE_UNSHARE
+#define CLOSE_RANGE_UNSHARE    (1U << 1)
+#endif
+
+#ifndef CLOSE_RANGE_CLOEXEC
+#define CLOSE_RANGE_CLOEXEC    (1U << 2)
+#endif
+
+#ifndef HAVE_CLOSE_RANGE
+static inline int close_range(unsigned int fd, unsigned int max_fd, unsigned int flags)
+{
+       return syscall(__NR_close_range, fd, max_fd, flags);
+}
+#endif
+
 #endif /* __LXC_SYSCALL_WRAPPER_H */