From 286286283e9bdc7ef894306e2dbcf4c115b97ba2 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Wed, 10 Mar 2021 12:26:31 -0300 Subject: linux: Add close_range It was added on Linux 5.9 (278a5fbaed89) with CLOSE_RANGE_CLOEXEC added on 5.11 (582f1fb6b721f). Although FreeBSD has added the same syscall, this only adds the symbol on Linux ports. This syscall is required to provided a fail-safe way to implement the closefrom symbol (BZ #10353). Checked on x86_64-linux-gnu and i686-linux-gnu on kernel 5.11 and 4.15. --- sysdeps/unix/sysv/linux/bits/unistd_ext.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'sysdeps/unix/sysv/linux/bits') diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h index 2e529be577..ae9994403c 100644 --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h @@ -33,4 +33,27 @@ not detached and has not been joined. */ extern __pid_t gettid (void) __THROW; +#ifdef __has_include +# if __has_include ("linux/close_range.h") +# include "linux/close_range.h" +# endif #endif +/* Unshare the file descriptor table before closing file descriptors. */ +#ifndef CLOSE_RANGE_UNSHARE +# define CLOSE_RANGE_UNSHARE (1U << 1) +#endif +/* Set the FD_CLOEXEC bit instead of closing the file descriptor. */ +#ifndef CLOSE_RANGE_CLOEXEC +# define CLOSE_RANGE_CLOEXEC (1U << 2) +#endif + +/* Close all file descriptors in the range FD up to MAX_FD. The flag FLAGS + are define by the CLOSE_RANGE prefix. This function behaves like close + on the range, but in a fail-safe where it will either fail and not close + any file descriptor or close all of them. Gaps where the file descriptor + is invalid are ignored. Returns 0 on successor or -1 for failure (and + sets errno accordingly). */ +extern int close_range (unsigned int __fd, unsigned int __max_fd, + int __flags) __THROW; + +#endif /* __USE_GNU */ -- cgit 1.4.1