xref: /dflybsd-src/lib/libc/gen/posix_spawn_file_actions_addopen.3 (revision c9c6988b3417c76f002af80950e0b3264917d3b1)
1c4dd129bSPeter Avalos.\" Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
2c4dd129bSPeter Avalos.\" All rights reserved.
3c4dd129bSPeter Avalos.\"
4c4dd129bSPeter Avalos.\" Redistribution and use in source and binary forms, with or without
5c4dd129bSPeter Avalos.\" modification, are permitted provided that the following conditions
6c4dd129bSPeter Avalos.\" are met:
7c4dd129bSPeter Avalos.\" 1. Redistributions of source code must retain the above copyright
8c4dd129bSPeter Avalos.\"    notice, this list of conditions and the following disclaimer.
9c4dd129bSPeter Avalos.\" 2. Redistributions in binary form must reproduce the above copyright
10c4dd129bSPeter Avalos.\"    notice, this list of conditions and the following disclaimer in the
11c4dd129bSPeter Avalos.\"    documentation and/or other materials provided with the distribution.
12c4dd129bSPeter Avalos.\"
13c4dd129bSPeter Avalos.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14c4dd129bSPeter Avalos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15c4dd129bSPeter Avalos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16c4dd129bSPeter Avalos.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17c4dd129bSPeter Avalos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18c4dd129bSPeter Avalos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19c4dd129bSPeter Avalos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20c4dd129bSPeter Avalos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21c4dd129bSPeter Avalos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22c4dd129bSPeter Avalos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23c4dd129bSPeter Avalos.\" SUCH DAMAGE.
24c4dd129bSPeter Avalos.\"
25c4dd129bSPeter Avalos.\" Portions of this text are reprinted and reproduced in electronic form
26c4dd129bSPeter Avalos.\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
27c4dd129bSPeter Avalos.\" Portable Operating System Interface (POSIX), The Open Group Base
28c4dd129bSPeter Avalos.\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
29c4dd129bSPeter Avalos.\" Electrical and Electronics Engineers, Inc and The Open Group.  In the
30c4dd129bSPeter Avalos.\" event of any discrepancy between this version and the original IEEE and
31c4dd129bSPeter Avalos.\" The Open Group Standard, the original IEEE and The Open Group Standard is
32c4dd129bSPeter Avalos.\" the referee document.  The original Standard can be obtained online at
33c4dd129bSPeter Avalos.\"	http://www.opengroup.org/unix/online.html.
34c4dd129bSPeter Avalos.\"
35c4dd129bSPeter Avalos.\" $FreeBSD: src/lib/libc/gen/posix_spawn_file_actions_addopen.3,v 1.2 2008/07/28 09:36:56 ed Exp $
36c4dd129bSPeter Avalos.\"
37bb5b9becSSascha Wildner.Dd February 22, 2018
38c4dd129bSPeter Avalos.Dt POSIX_SPAWN_FILE_ACTIONS_ADDOPEN 3
39c4dd129bSPeter Avalos.Os
40c4dd129bSPeter Avalos.Sh NAME
41c4dd129bSPeter Avalos.Nm posix_spawn_file_actions_addopen ,
42c4dd129bSPeter Avalos.Nm posix_spawn_file_actions_adddup2 ,
43c4dd129bSPeter Avalos.Nm posix_spawn_file_actions_addclose
44c4dd129bSPeter Avalos.Nd "add open, dup2 or close action to spawn file actions object"
45c4dd129bSPeter Avalos.Sh LIBRARY
46c4dd129bSPeter Avalos.Lb libc
47c4dd129bSPeter Avalos.Sh SYNOPSIS
48c4dd129bSPeter Avalos.In spawn.h
49c4dd129bSPeter Avalos.Ft int
50bb5b9becSSascha Wildner.Fn posix_spawn_file_actions_addopen "posix_spawn_file_actions_t * restrict file_actions" "int fildes" "const char * restrict path" "int oflag" "mode_t mode"
51c4dd129bSPeter Avalos.Ft int
52c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_adddup2 "posix_spawn_file_actions_t * file_actions" "int fildes" "int newfildes"
53c4dd129bSPeter Avalos.Ft int
54c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_addclose "posix_spawn_file_actions_t * file_actions" "int fildes"
55c4dd129bSPeter Avalos.Sh DESCRIPTION
56c4dd129bSPeter AvalosThese functions add an open, dup2 or close action to a spawn
57c4dd129bSPeter Avalosfile actions object.
58c4dd129bSPeter Avalos.Pp
59c4dd129bSPeter AvalosA spawn file actions object is of type
60c4dd129bSPeter Avalos.Vt posix_spawn_file_actions_t
61c4dd129bSPeter Avalos(defined in
62c4dd129bSPeter Avalos.In spawn.h )
63c4dd129bSPeter Avalosand is used to specify a series of actions to be performed by a
64c4dd129bSPeter Avalos.Fn posix_spawn
65c4dd129bSPeter Avalosor
66c4dd129bSPeter Avalos.Fn posix_spawnp
67c4dd129bSPeter Avalosoperation in order to arrive at the set of open file descriptors for the
68c4dd129bSPeter Avaloschild process given the set of open file descriptors of the parent.
69c4dd129bSPeter Avalos.Pp
70c4dd129bSPeter AvalosA spawn file actions object, when passed to
71c4dd129bSPeter Avalos.Fn posix_spawn
72c4dd129bSPeter Avalosor
73c4dd129bSPeter Avalos.Fn posix_spawnp ,
74c4dd129bSPeter Avalosspecify how the set of open file descriptors in the calling
75c4dd129bSPeter Avalosprocess is transformed into a set of potentially open file descriptors
76c4dd129bSPeter Avalosfor the spawned process.
77c4dd129bSPeter AvalosThis transformation is as if the specified sequence of actions was
78c4dd129bSPeter Avalosperformed exactly once, in the context of the spawned process (prior to
79c4dd129bSPeter Avalosexecution of the new process image), in the order in which the actions
80c4dd129bSPeter Avaloswere added to the object; additionally, when the new process image is
81c4dd129bSPeter Avalosexecuted, any file descriptor (from this new set) which has its
82c4dd129bSPeter Avalos.Dv FD_CLOEXEC
83c4dd129bSPeter Avalosflag set is closed (see
84c4dd129bSPeter Avalos.Fn posix_spawn ) .
85c4dd129bSPeter Avalos.Pp
86c4dd129bSPeter AvalosThe
87c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_addopen
88c4dd129bSPeter Avalosfunction adds an open action to the object referenced by
89c4dd129bSPeter Avalos.Fa file_actions
90c4dd129bSPeter Avalosthat causes the file named by
91c4dd129bSPeter Avalos.Fa path
92c4dd129bSPeter Avalosto be opened (as if
93c4dd129bSPeter Avalos.Bd -literal -offset indent
94c4dd129bSPeter Avalosopen(path, oflag, mode)
95c4dd129bSPeter Avalos.Ed
96c4dd129bSPeter Avalos.Pp
97c4dd129bSPeter Avaloshad been called, and the returned file descriptor, if not
98c4dd129bSPeter Avalos.Fa fildes ,
99c4dd129bSPeter Avaloshad been changed to
100c4dd129bSPeter Avalos.Fa fildes )
101c4dd129bSPeter Avaloswhen a new process is spawned using this file actions object.
102c4dd129bSPeter AvalosIf
103c4dd129bSPeter Avalos.Fa fildes
104c4dd129bSPeter Avaloswas already an open file descriptor, it is closed before the new
105c4dd129bSPeter Avalosfile is opened.
106c4dd129bSPeter Avalos.Pp
107c4dd129bSPeter AvalosThe string described by
108c4dd129bSPeter Avalos.Fa path
109c4dd129bSPeter Avalosis copied by the
110c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_addopen
111c4dd129bSPeter Avalosfunction.
112c4dd129bSPeter Avalos.Pp
113c4dd129bSPeter AvalosThe
114c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_adddup2
115c4dd129bSPeter Avalosfunction adds a dup2 action to the object referenced by
116c4dd129bSPeter Avalos.Fa file_actions
117c4dd129bSPeter Avalosthat causes the file descriptor
118c4dd129bSPeter Avalos.Fa fildes
119c4dd129bSPeter Avalosto be duplicated as
120c4dd129bSPeter Avalos.Fa newfildes
121c4dd129bSPeter Avalos(as if
122c4dd129bSPeter Avalos.Bd -literal -offset indent
123c4dd129bSPeter Avalosdup2(fildes, newfildes)
124c4dd129bSPeter Avalos.Ed
125c4dd129bSPeter Avalos.Pp
126c4dd129bSPeter Avaloshad been called) when a new process is spawned using this file actions object.
127c4dd129bSPeter Avalos.Pp
128c4dd129bSPeter AvalosThe
129c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_addclose
130c4dd129bSPeter Avalosfunction adds a close action to the object referenced by
131c4dd129bSPeter Avalos.Fa file_actions
132c4dd129bSPeter Avalosthat causes the file descriptor
133c4dd129bSPeter Avalos.Fa fildes
134c4dd129bSPeter Avalosto be closed (as if
135c4dd129bSPeter Avalos.Bd -literal -offset indent
136c4dd129bSPeter Avalosclose(fildes)
137c4dd129bSPeter Avalos.Ed
138c4dd129bSPeter Avalos.Pp
139c4dd129bSPeter Avaloshad been called) when a new process is spawned using this file actions
140c4dd129bSPeter Avalosobject.
141c4dd129bSPeter Avalos.Sh RETURN VALUES
142c4dd129bSPeter AvalosUpon successful completion, these functions return zero;
143c4dd129bSPeter Avalosotherwise, an error number is returned to indicate the error.
144c4dd129bSPeter Avalos.Sh ERRORS
145c4dd129bSPeter AvalosThese
146c4dd129bSPeter Avalosfunctions fail if:
147c4dd129bSPeter Avalos.Bl -tag -width Er
148c4dd129bSPeter Avalos.It Bq Er EINVAL
149c4dd129bSPeter AvalosThe value specified by
150c4dd129bSPeter Avalos.Fa fildes
151c4dd129bSPeter Avalosor
152c4dd129bSPeter Avalos.Fa newfildes
153c4dd129bSPeter Avalosis negative.
154c4dd129bSPeter Avalos.It Bq Er ENOMEM
155c4dd129bSPeter AvalosInsufficient memory exists to add to the spawn file actions object.
156c4dd129bSPeter Avalos.El
157c4dd129bSPeter Avalos.Sh SEE ALSO
158c4dd129bSPeter Avalos.Xr close 2 ,
159c4dd129bSPeter Avalos.Xr dup2 2 ,
160c4dd129bSPeter Avalos.Xr open 2 ,
161c4dd129bSPeter Avalos.Xr posix_spawn 3 ,
162c4dd129bSPeter Avalos.Xr posix_spawn_file_actions_destroy 3 ,
163c4dd129bSPeter Avalos.Xr posix_spawn_file_actions_init 3 ,
164c4dd129bSPeter Avalos.Xr posix_spawnp 3
165c4dd129bSPeter Avalos.Sh STANDARDS
166c4dd129bSPeter AvalosThe
167c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_addopen ,
168c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_adddup2
169c4dd129bSPeter Avalosand
170c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_addclose
171c4dd129bSPeter Avalosfunctions conform to
172c4dd129bSPeter Avalos.St -p1003.1-2001 .
173c4dd129bSPeter Avalos.Sh HISTORY
174c4dd129bSPeter AvalosThe
175c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_addopen ,
176c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_adddup2
177c4dd129bSPeter Avalosand
178c4dd129bSPeter Avalos.Fn posix_spawn_file_actions_addclose
179c4dd129bSPeter Avalosfunctions first appeared in
180c4dd129bSPeter Avalos.Fx 8.0 .
181c4dd129bSPeter Avalos.Sh AUTHORS
182*c9c6988bSSascha Wildner.An \&Ed Schouten Aq Mt ed@FreeBSD.org
183