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