~ubuntu-branches/ubuntu/precise/manpages-posix/precise

1 by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages.
1
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved 
2 by Francesco Paolo Lovergine
* Alligned to linux main manpages edition.
2
.TH "POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
1 by Francesco Paolo Lovergine
rules: linking manpages-posix not manpages.
3
.\" posix_spawn_file_actions_addclose 
4
.SH NAME
5
posix_spawn_file_actions_addclose, posix_spawn_file_actions_addopen
6
\- add close or open action to spawn file actions
7
object (\fBADVANCED REALTIME\fP)
8
.SH SYNOPSIS
9
.LP
10
\fB#include <spawn.h>
11
.br
12
.sp
13
int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *
14
.br
15
\ \ \ \ \ \ \fP \fIfile_actions\fP\fB, int\fP \fIfildes\fP\fB);
16
.br
17
int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *
18
.br
19
\ \ \ \ \ \  restrict\fP \fIfile_actions\fP\fB, int\fP \fIfildes\fP\fB,
20
.br
21
\ \ \ \ \ \  const char *restrict\fP \fIpath\fP\fB, int\fP \fIoflag\fP\fB,
22
mode_t\fP
23
\fImode\fP\fB); \fP
24
\fB
25
.br
26
\fP
27
.SH DESCRIPTION
28
.LP
29
These functions shall add or delete a close or open action to a spawn
30
file actions object.
31
.LP
32
A spawn file actions object is of type \fBposix_spawn_file_actions_t\fP
33
(defined in \fI<spawn.h>\fP) and is used to specify a series of actions
34
to be performed by a \fIposix_spawn\fP() or \fIposix_spawnp\fP()
35
operation in order to arrive at the set of open file descriptors for
36
the child process given the set of open file descriptors of
37
the parent. IEEE\ Std\ 1003.1-2001 does not define comparison or assignment
38
operators for the type
39
\fBposix_spawn_file_actions_t\fP.
40
.LP
41
A spawn file actions object, when passed to \fIposix_spawn\fP() or
42
\fIposix_spawnp\fP(), shall specify how the set of open file descriptors
43
in the calling
44
process is transformed into a set of potentially open file descriptors
45
for the spawned process. This transformation shall be as if
46
the specified sequence of actions was performed exactly once, in the
47
context of the spawned process (prior to execution of the new
48
process image), in the order in which the actions were added to the
49
object; additionally, when the new process image is executed,
50
any file descriptor (from this new set) which has its FD_CLOEXEC flag
51
set shall be closed (see \fIposix_spawn\fP() ).
52
.LP
53
The \fIposix_spawn_file_actions_addclose\fP() function shall add a
54
\fIclose\fP action to the object referenced by
55
\fIfile_actions\fP that shall cause the file descriptor \fIfildes\fP
56
to be closed (as if \fIclose\fP( \fIfildes\fP) had been
57
called) when a new process is spawned using this file actions object.
58
.LP
59
The \fIposix_spawn_file_actions_addopen\fP() function shall add an
60
\fIopen\fP action to the object referenced by
61
\fIfile_actions\fP that shall cause the file named by \fIpath\fP to
62
be opened (as if \fIopen\fP( \fIpath\fP, \fIoflag\fP,
63
\fImode\fP) had been called, and the returned file descriptor, if
64
not \fIfildes\fP, had been changed to \fIfildes\fP) when a new
65
process is spawned using this file actions object. If \fIfildes\fP
66
was already an open file descriptor, it shall be closed before
67
the new file is opened.
68
.LP
69
The string described by \fIpath\fP shall be copied by the \fIposix_spawn_file_actions_addopen\fP()
70
function.
71
.SH RETURN VALUE
72
.LP
73
Upon successful completion, these functions shall return zero; otherwise,
74
an error number shall be returned to indicate the
75
error.
76
.SH ERRORS
77
.LP
78
These functions shall fail if:
79
.TP 7
80
.B EBADF
81
The value specified by \fIfildes\fP is negative or greater than or
82
equal to {OPEN_MAX}.
83
.sp
84
.LP
85
These functions may fail if:
86
.TP 7
87
.B EINVAL
88
The value specified by \fIfile_actions\fP is invalid.
89
.TP 7
90
.B ENOMEM
91
Insufficient memory exists to add to the spawn file actions object.
92
.sp
93
.LP
94
It shall not be considered an error for the \fIfildes\fP argument
95
passed to these functions to specify a file descriptor for
96
which the specified operation could not be performed at the time of
97
the call. Any such error will be detected when the associated
98
file actions object is later used during a \fIposix_spawn\fP() or
99
\fIposix_spawnp\fP() operation.
100
.LP
101
\fIThe following sections are informative.\fP
102
.SH EXAMPLES
103
.LP
104
None.
105
.SH APPLICATION USAGE
106
.LP
107
These functions are part of the Spawn option and need not be provided
108
on all implementations.
109
.SH RATIONALE
110
.LP
111
A spawn file actions object may be initialized to contain an ordered
112
sequence of \fIclose\fP(), \fIdup2\fP(), and \fIopen\fP() operations
113
to be used by \fIposix_spawn\fP() or \fIposix_spawnp\fP() to
114
arrive at the set of open file descriptors inherited by the spawned
115
process from the set of open file descriptors in the parent at
116
the time of the \fIposix_spawn\fP() or \fIposix_spawnp\fP() call.
117
It had been suggested that the \fIclose\fP() and \fIdup2\fP() operations
118
alone are sufficient
119
to rearrange file descriptors, and that files which need to be opened
120
for use by the spawned process can be handled either by
121
having the calling process open them before the \fIposix_spawn\fP()
122
or \fIposix_spawnp\fP() call (and close them after), or by passing
123
filenames to the spawned
124
process (in \fIargv\fP) so that it may open them itself. The standard
125
developers recommend that applications use one of these two
126
methods when practical, since detailed error status on a failed open
127
operation is always available to the application this way.
128
However, the standard developers feel that allowing a spawn file actions
129
object to specify open operations is still appropriate
130
because:
131
.IP " 1." 4
132
It is consistent with equivalent POSIX.5 (Ada) functionality.
133
.LP
134
.IP " 2." 4
135
It supports the I/O redirection paradigm commonly employed by POSIX
136
programs designed to be invoked from a shell. When such a
137
program is the child process, it may not be designed to open files
138
on its own.
139
.LP
140
.IP " 3." 4
141
It allows file opens that might otherwise fail or violate file ownership/access
142
rights if executed by the parent process.
143
.LP
144
.LP
145
Regarding 2. above, note that the spawn open file action provides
146
to \fIposix_spawn\fP() and \fIposix_spawnp\fP() the
147
same capability that the shell redirection operators provide to \fIsystem\fP(),
148
only
149
without the intervening execution of a shell; for example:
150
.sp
151
.RS
152
.nf
153
154
\fBsystem ("myprog <file1 3<file2");
155
\fP
156
.fi
157
.RE
158
.LP
159
Regarding 3. above, note that if the calling process needs to open
160
one or more files for access by the spawned process, but has
161
insufficient spare file descriptors, then the open action is necessary
162
to allow the \fIopen\fP() to occur in the context of the child process
163
after other file descriptors have been
164
closed (that must remain open in the parent).
165
.LP
166
Additionally, if a parent is executed from a file having a "set-user-id"
167
mode bit set and the POSIX_SPAWN_RESETIDS flag is set
168
in the spawn attributes, a file created within the parent process
169
will (possibly incorrectly) have the parent's effective user ID
170
as its owner, whereas a file created via an \fIopen\fP() action during
171
\fIposix_spawn\fP() or \fIposix_spawnp\fP() will
172
have the parent's real ID as its owner; and an open by the parent
173
process may successfully open a file to which the real user
174
should not have access or fail to open a file to which the real user
175
should have access.
176
.SS File Descriptor Mapping
177
.LP
178
The standard developers had originally proposed using an array which
179
specified the mapping of child file descriptors back to
180
those of the parent. It was pointed out by the ballot group that it
181
is not possible to reshuffle file descriptors arbitrarily in a
182
library implementation of \fIposix_spawn\fP() or \fIposix_spawnp\fP()
183
without provision for one or more spare file descriptor entries (which
184
simply may not be available). Such an array requires that an implementation
185
develop a complex strategy to achieve the desired
186
mapping without inadvertently closing the wrong file descriptor at
187
the wrong time.
188
.LP
189
It was noted by a member of the Ada Language Bindings working group
190
that the approved Ada Language \fIStart_Process\fP family
191
of POSIX process primitives use a caller-specified set of file actions
192
to alter the normal \fIfork\fP()/ \fIexec\fP semantics for inheritance
193
of file
194
descriptors in a very flexible way, yet no such problems exist because
195
the burden of determining how to achieve the final file
196
descriptor mapping is completely on the application. Furthermore,
197
although the file actions interface appears frightening at first
198
glance, it is actually quite simple to implement in either a library
199
or the kernel.
200
.SH FUTURE DIRECTIONS
201
.LP
202
None.
203
.SH SEE ALSO
204
.LP
205
\fIclose\fP() , \fIdup\fP() , \fIopen\fP() , \fIposix_spawn\fP() ,
206
\fIposix_spawn_file_actions_adddup2\fP() , \fIposix_spawn_file_actions_destroy\fP()
207
, \fIposix_spawnp\fP() , the Base Definitions volume of IEEE\ Std\ 1003.1-2001,
208
\fI<spawn.h>\fP
209
.SH COPYRIGHT
210
Portions of this text are reprinted and reproduced in electronic form
211
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
212
-- Portable Operating System Interface (POSIX), The Open Group Base
213
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
214
Electrical and Electronics Engineers, Inc and The Open Group. In the
215
event of any discrepancy between this version and the original IEEE and
216
The Open Group Standard, the original IEEE and The Open Group Standard
217
is the referee document. The original Standard can be obtained online at
218
http://www.opengroup.org/unix/online.html .