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