Skip to content

Commit 3b9c824

Browse files
Add manpages for O_CLOFORK flag and others
1 parent 6ce27ee commit 3b9c824

File tree

10 files changed

+138
-24
lines changed

10 files changed

+138
-24
lines changed

lib/libc/gen/dup3.3

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2323
.\" SUCH DAMAGE.
2424
.\"
25-
.Dd August 16, 2013
25+
.Dd May 17, 2025
2626
.Dt DUP3 3
2727
.Os
2828
.Sh NAME
@@ -47,6 +47,11 @@ The close-on-exec flag on the new file descriptor is determined by the
4747
bit in
4848
.Fa flags .
4949
.Pp
50+
The close-on-fork flag on the new file descriptor is determined by the
51+
.Dv O_CLOFORK
52+
bit in
53+
.Fa flags .
54+
.Pp
5055
If
5156
.Fa oldd
5257
\*(Ne
@@ -91,7 +96,9 @@ argument.
9196
The
9297
.Fa flags
9398
argument has bits set other than
94-
.Dv O_CLOEXEC .
99+
.Dv O_CLOEXEC
100+
or
101+
.Dv O_CLOFORK .
95102
.El
96103
.Sh SEE ALSO
97104
.Xr accept 2 ,
@@ -112,3 +119,7 @@ The
112119
.Fn dup3
113120
function appeared in
114121
.Fx 10.0 .
122+
The
123+
.Dv O_CLOFORK
124+
flag appeared in
125+
.Fx 15.0 .

lib/libsys/accept.2

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626
.\" SUCH DAMAGE.
2727
.\"
28-
.Dd October 9, 2014
28+
.Dd May 17, 2025
2929
.Dt ACCEPT 2
3030
.Os
3131
.Sh NAME
@@ -85,6 +85,13 @@ and the close-on-exec flag on the new file descriptor can be set via the
8585
flag in the
8686
.Fa flags
8787
argument.
88+
Similarly, the
89+
.Dv O_CLOFORK
90+
property can be set via the
91+
.Dv SOCK_CLOFORK
92+
flag in the
93+
.Fa flags
94+
argument.
8895
.Pp
8996
If no pending connections are
9097
present on the queue, and the original socket
@@ -234,3 +241,8 @@ The
234241
.Fn accept4
235242
system call appeared in
236243
.Fx 10.0 .
244+
.Pp
245+
The
246+
.Dv SOCK_CLOFORK
247+
flag appeared in
248+
.Fx 15.0 .

lib/libsys/closefrom.2

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2424
.\" SUCH DAMAGE.
2525
.\"
26-
.Dd March 3, 2022
26+
.Dd May 17, 2025
2727
.Dt CLOSEFROM 2
2828
.Os
2929
.Sh NAME
@@ -60,6 +60,10 @@ Supported
6060
.It Dv CLOSE_RANGE_CLOEXEC
6161
Set the close-on-exec flag on descriptors in the range instead of closing them.
6262
.El
63+
.Bl -tag -width ".Dv CLOSE_RANGE_CLOFORK"
64+
.It Dv CLOSE_RANGE_CLOFORK
65+
Set the close-on-fork flag on descriptors in the range instead of closing them.
66+
.El
6367
.Sh RETURN VALUES
6468
Upon successful completion,
6569
.Fn close_range
@@ -90,3 +94,8 @@ The
9094
.Fn closefrom
9195
function first appeared in
9296
.Fx 8.0 .
97+
.Pp
98+
The
99+
.Dv CLOSE_RANGE_CLOFORK
100+
flag appeared in
101+
.Fx 15.0 .

lib/libsys/fcntl.2

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626
.\" SUCH DAMAGE.
2727
.\"
28-
.Dd December 7, 2021
28+
.Dd May 17, 2025
2929
.Dt FCNTL 2
3030
.Os
3131
.Sh NAME
@@ -80,6 +80,13 @@ associated with the new file descriptor is cleared, so the file descriptor is
8080
to remain open across
8181
.Xr execve 2
8282
system calls.
83+
.It
84+
The fork-on-exec flag
85+
.Dv FD_CLOFORK
86+
associated with the new file descriptor is cleared, so the file descriptor is
87+
to remain open across
88+
.Xr fork 2
89+
system calls.
8390
.El
8491
.It Dv F_DUPFD_CLOEXEC
8592
Like
@@ -90,6 +97,15 @@ flag associated with the new file descriptor is set, so the file descriptor
9097
is closed when
9198
.Xr execve 2
9299
system call executes.
100+
.It Dv F_DUPFD_CLOFORK
101+
Like
102+
.Dv F_DUPFD ,
103+
but the
104+
.Dv FD_CLOFORK
105+
flag associated with the new file descriptor is set, so the file descriptor
106+
is closed when
107+
.Xr fork 2
108+
system call executes.
93109
.It Dv F_DUP2FD
94110
It is functionally equivalent to
95111
.Bd -literal -offset indent
@@ -101,22 +117,32 @@ Like
101117
but the
102118
.Dv FD_CLOEXEC
103119
flag associated with the new file descriptor is set.
120+
.It Dv F_DUP2FD_CLOFORK
121+
Like
122+
.Dv F_DUP2FD ,
123+
but the
124+
.Dv FD_CLOFORK
125+
flag associated with the new file descriptor is set.
104126
.Pp
105127
The
106128
.Dv F_DUP2FD
107-
and
129+
,
108130
.Dv F_DUP2FD_CLOEXEC
131+
and
132+
.Dv F_DUP2FD_CLOFORK
109133
constants are not portable, so they should not be used if
110134
portability is needed.
111135
Use
112136
.Fn dup2
113137
instead of
114138
.Dv F_DUP2FD .
139+
.It Dv F_DUP3FD
140+
Used to implement the
141+
.Fn dup3
142+
call. Do not use it.
115143
.It Dv F_GETFD
116-
Get the close-on-exec flag associated with the file descriptor
144+
Get the close-on-exec and close-on-fork flags associated with the file descriptor
117145
.Fa fd
118-
as
119-
.Dv FD_CLOEXEC .
120146
If the returned value ANDed with
121147
.Dv FD_CLOEXEC
122148
is 0,
@@ -125,16 +151,19 @@ the file will remain open across
125151
otherwise the file will be closed upon execution of
126152
.Fn exec
127153
.Fa ( arg
128-
is ignored).
154+
is ignored). The same happens with
155+
.Dv FD_CLOFORK .
129156
.It Dv F_SETFD
130-
Set the close-on-exec flag associated with
157+
Set the close-on-exec and close-on-fork flags associated with
131158
.Fa fd
132159
to
133160
.Fa arg ,
134161
where
135162
.Fa arg
136-
is either 0 or
137-
.Dv FD_CLOEXEC ,
163+
is either 0,
164+
.Dv FD_CLOEXEC
165+
or
166+
.Dv FD_CLOFORK
138167
as described above.
139168
.It Dv F_GETFL
140169
Get descriptor status flags, as described below
@@ -762,8 +791,10 @@ for the reasons as stated in
762791
.Sh STANDARDS
763792
The
764793
.Dv F_DUP2FD
765-
constant is non portable.
766-
It is provided for compatibility with AIX and Solaris.
794+
and
795+
.Dv F_DUP3FD
796+
constants are not portable.
797+
They are provided for compatibility with AIX and Solaris.
767798
.Pp
768799
Per
769800
.St -susv4 ,
@@ -788,3 +819,12 @@ The
788819
.Dv F_DUP2FD
789820
constant first appeared in
790821
.Fx 7.1 .
822+
.Pp
823+
The
824+
.Dv F_DUPFD_CLOFORK
825+
,
826+
.Dv F_DUP2FD_CLOFORK
827+
and
828+
.Dv F_DUP3FD
829+
flags appeared in
830+
.Fx 15.0 .

lib/libsys/fork.2

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626
.\" SUCH DAMAGE.
2727
.\"
28-
.Dd August 5, 2021
28+
.Dd May 17, 2024
2929
.Dt FORK 2
3030
.Os
3131
.Sh NAME
@@ -68,6 +68,15 @@ by the parent.
6868
This descriptor copying is also used by the shell to
6969
establish standard input and output for newly created processes
7070
as well as to set up pipes.
71+
Any file descriptors that were marked with the close-on-fork flag,
72+
.Dv FD_CLOFORK
73+
(see
74+
.Fn fcntl 2
75+
and
76+
.Dv O_CLOFORK
77+
in
78+
.Fn open 2
79+
), will not be present in the child process, but remain open in the parent.
7180
.It
7281
The child process' resource utilizations
7382
are set to 0; see

lib/libsys/open.2

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626
.\" SUCH DAMAGE.
2727
.\"
28-
.Dd February 28, 2025
28+
.Dd May 17, 2025
2929
.Dt OPEN 2
3030
.Os
3131
.Sh NAME
@@ -195,6 +195,16 @@ error if file is not a directory
195195
.It Dv O_CLOEXEC
196196
automatically close file on
197197
.Xr execve 2
198+
.It Dv O_CLOFORK
199+
If set, the file descriptor returned will be closed in any child processses created with the
200+
.Fn fork 2
201+
family of functions. The file descriptor will remain open in the parent.
202+
This sets the
203+
.Dv FD_CLOFORK flag on the file descriptor.
204+
If not performed at open time, this can later be set with the
205+
.Dv F_SETFD
206+
.Fn fcntl 2
207+
command.
198208
.It Dv O_VERIFY
199209
verify the contents of the file with
200210
.Xr mac_veriexec 4
@@ -793,7 +803,12 @@ The
793803
function was introduced in
794804
.Fx 8.0 .
795805
.Dv O_DSYNC
796-
appeared in 13.0.
806+
appeared in
807+
.Fx 13.0 .
808+
.Pp
809+
.Dv O_CLOFORK
810+
flag appeared in
811+
.Fx 15.0 .
797812
.Sh BUGS
798813
The
799814
.Fa mode

lib/libsys/pipe.2

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626
.\" SUCH DAMAGE.
2727
.\"
28-
.Dd December 1, 2017
28+
.Dd May 17, 2025
2929
.Dt PIPE 2
3030
.Os
3131
.Sh NAME
@@ -64,6 +64,8 @@ list, defined in
6464
.Bl -tag -width ".Dv O_NONBLOCK"
6565
.It Dv O_CLOEXEC
6666
Set the close-on-exec flag for the new file descriptors.
67+
.It Dv O_CLOFORK
68+
Set the close-on-fork flag for the new file descriptors.
6769
.It Dv O_NONBLOCK
6870
Set the non-blocking flag for the ends of the pipe.
6971
.El
@@ -173,3 +175,8 @@ function became a wrapper around
173175
.Fn pipe2
174176
in
175177
.Fx 11.0 .
178+
.Pp
179+
The
180+
.Dv O_CLOFORK
181+
flag appeared in
182+
.Fx 15.0 .

lib/libsys/recv.2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626
.\" SUCH DAMAGE.
2727
.\"
28-
.Dd July 30, 2022
28+
.Dd May 17, 2025
2929
.Dt RECV 2
3030
.Os
3131
.Sh NAME
@@ -164,6 +164,7 @@ one or more of the values:
164164
.It Dv MSG_WAITALL Ta wait for full request or error
165165
.It Dv MSG_DONTWAIT Ta do not block
166166
.It Dv MSG_CMSG_CLOEXEC Ta set received fds close-on-exec
167+
.It Dv MSG_CMSG_CLOFORK Ta set received fds close-on-fork
167168
.It Dv MSG_WAITFORONE Ta do not block after receiving the first message
168169
(only for
169170
.Fn recvmmsg

lib/libsys/socket.2

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626
.\" SUCH DAMAGE.
2727
.\"
28-
.Dd January 15, 2023
28+
.Dd May 17, 2025
2929
.Dt SOCKET 2
3030
.Os
3131
.Sh NAME
@@ -121,6 +121,7 @@ argument:
121121
.Pp
122122
.Bd -literal -offset indent -compact
123123
SOCK_CLOEXEC Set close-on-exec on the new descriptor,
124+
SOCK_CLOFORK Set close-on-fork on the new descriptor,
124125
SOCK_NONBLOCK Set non-blocking mode on the new socket
125126
.Ed
126127
.Pp
@@ -331,7 +332,10 @@ argument of
331332
.Fn socket .
332333
The
333334
.Dv SOCK_CLOEXEC
334-
flag is expected to conform to the next revision of the
335+
and
336+
.Dv SOCK_CLOFORK
337+
flags are expected to conform to
338+
.St -p1003.1-2024 .
335339
.Tn POSIX
336340
standard.
337341
The
@@ -347,3 +351,8 @@ The
347351
.Fn socket
348352
system call appeared in
349353
.Bx 4.2 .
354+
.Pp
355+
The
356+
.Dv SOCK_CLOFORK
357+
flag appeared in
358+
.Fx 15.0 .

lib/libsys/socketpair.2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626
.\" SUCH DAMAGE.
2727
.\"
28-
.Dd February 10, 2018
28+
.Dd May 17, 2025
2929
.Dt SOCKETPAIR 2
3030
.Os
3131
.Sh NAME
@@ -56,7 +56,8 @@ and
5656
The two sockets are indistinguishable.
5757
.Pp
5858
The
59-
.Dv SOCK_CLOEXEC
59+
.Dv SOCK_CLOEXEC ,
60+
.Dv SOCK_CLOFORK
6061
and
6162
.Dv SOCK_NONBLOCK
6263
flags in the

0 commit comments

Comments
 (0)