aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/bits
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-03-10 12:26:31 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-07-08 14:08:13 -0300
commit286286283e9bdc7ef894306e2dbcf4c115b97ba2 (patch)
tree00fa61df0e6e6093c337bc59a6c5fdd914d9fe6f /sysdeps/unix/sysv/linux/bits
parentae8c243d2473bdfc3c0f9c6b46e6dffb5a28725c (diff)
downloadglibc-286286283e9bdc7ef894306e2dbcf4c115b97ba2.tar
glibc-286286283e9bdc7ef894306e2dbcf4c115b97ba2.tar.gz
glibc-286286283e9bdc7ef894306e2dbcf4c115b97ba2.tar.bz2
glibc-286286283e9bdc7ef894306e2dbcf4c115b97ba2.zip
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.
Diffstat (limited to 'sysdeps/unix/sysv/linux/bits')
-rw-r--r--sysdeps/unix/sysv/linux/bits/unistd_ext.h23
1 files changed, 23 insertions, 0 deletions
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 */