summaryrefslogtreecommitdiffstats
path: root/man2/close_range.2
diff options
context:
space:
mode:
Diffstat (limited to 'man2/close_range.2')
-rw-r--r--man2/close_range.235
1 files changed, 19 insertions, 16 deletions
diff --git a/man2/close_range.2 b/man2/close_range.2
index c1aa3db..d9582b0 100644
--- a/man2/close_range.2
+++ b/man2/close_range.2
@@ -3,7 +3,7 @@
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
-.TH close_range 2 2023-05-03 "Linux man-pages 6.05.01"
+.TH close_range 2 2024-02-25 "Linux man-pages 6.7"
.SH NAME
close_range \- close all file descriptors in a given range
.SH LIBRARY
@@ -11,10 +11,14 @@ Standard C library
.RI ( libc ", " \-lc )
.SH SYNOPSIS
.nf
-.B #include <linux/close_range.h>
-.PP
-.BI "int close_range(unsigned int " first ", unsigned int " last ,
-.BI " unsigned int " flags );
+.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
+.B #include <unistd.h>
+.P
+.BR "#include <linux/close_range.h>" " /* Definition of " CLOSE_RANGE_*
+.BR "" " constants */"
+.P
+.BI "int close_range(unsigned int " first ", unsigned int " last \
+", int " flags );
.fi
.SH DESCRIPTION
The
@@ -24,9 +28,9 @@ system call closes all open file descriptors from
to
.I last
(included).
-.PP
+.P
Errors closing a given file descriptor are currently ignored.
-.PP
+.P
.I flags
is a bit mask containing 0 or more of the following:
.TP
@@ -53,7 +57,7 @@ is not valid, or
.I first
is greater than
.IR last .
-.PP
+.P
The following can occur with
.B CLOSE_RANGE_UNSHARE
(when constructing the new descriptor table):
@@ -97,7 +101,7 @@ which provides significant performance benefits.
.SS Closing file descriptors before exec
.\" 60997c3d45d9a67daf01c56d805ae4fec37e0bd8
File descriptors can be closed safely using
-.PP
+.P
.in +4n
.EX
/* we don't want anything past stderr here */
@@ -105,17 +109,17 @@ close_range(3, \[ti]0U, CLOSE_RANGE_UNSHARE);
execve(....);
.EE
.in
-.PP
+.P
.B CLOSE_RANGE_UNSHARE
is conceptually equivalent to
-.PP
+.P
.in +4n
.EX
unshare(CLONE_FILES);
close_range(first, last, 0);
.EE
.in
-.PP
+.P
but can be more efficient:
if the unshared range extends past
the current maximum number of file descriptors allocated
@@ -168,7 +172,7 @@ uses
to close all file descriptors greater than or equal to 3,
and then once more displays the process's list of open files.
The following example demonstrates the use of the program:
-.PP
+.P
.in +4n
.EX
$ \fBtouch /tmp/a /tmp/b /tmp/c\fP
@@ -190,7 +194,7 @@ $ \fB./a.out /tmp/a /tmp/b /tmp/c\fP
/proc/self/fd/3 ==> /proc/9005/fd
.EE
.in
-.PP
+.P
Note that the lines showing the pathname
.I /proc/9005/fd
result from the calls to
@@ -205,7 +209,6 @@ result from the calls to
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
-#include <sys/syscall.h>
#include <unistd.h>
\&
/* Show the contents of the symbolic links in /proc/self/fd */
@@ -259,7 +262,7 @@ main(int argc, char *argv[])
\&
printf("========= About to call close_range() =======\en");
\&
- if (syscall(SYS_close_range, 3, \[ti]0U, 0) == \-1) {
+ if (close_range(3, \[ti]0U, 0) == \-1) {
perror("close_range");
exit(EXIT_FAILURE);
}