1 /* Definitions for POSIX spawn interface.
2 Copyright (C) 2000, 2003, 2004, 2008-2009 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 @PRAGMA_SYSTEM_HEADER@
24 /* The include_next requires a split double-inclusion guard. */
26 # @INCLUDE_NEXT@ @NEXT_SPAWN_H@
34 #include <sys/types.h>
40 /* GCC 2.95 and later have "__restrict"; C99 compilers have
41 "restrict", and "configure" may have defined "restrict".
42 Other compilers use __restrict, __restrict__, and _Restrict, and
43 'configure' might #define 'restrict' to those words, so pick a
46 # if 199901L <= __STDC_VERSION__
47 # define _Restrict_ restrict
48 # elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
49 # define _Restrict_ __restrict
54 /* gcc 3.1 and up support the [restrict] syntax. Don't trust
55 sys/cdefs.h's definition of __restrict_arr, though, as it
56 mishandles gcc -ansi -pedantic. */
57 #ifndef _Restrict_arr_
58 # if ((199901L <= __STDC_VERSION__ \
59 || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \
60 && !__STRICT_ANSI__)) \
62 # define _Restrict_arr_ _Restrict_
64 # define _Restrict_arr_
68 /* The definition of GL_LINK_WARNING is copied here. */
70 /* The definition of _GL_ARG_NONNULL is copied here. */
73 /* Data structure to contain attributes for thread creation. */
74 #if @REPLACE_POSIX_SPAWN@
75 # define posix_spawnattr_t rpl_posix_spawnattr_t
77 #if @REPLACE_POSIX_SPAWN@ || !@HAVE_POSIX_SPAWNATTR_T@
84 struct sched_param _sp;
91 /* Data structure to contain information about the actions to be
92 performed in the new process with respect to file descriptors. */
93 #if @REPLACE_POSIX_SPAWN@
94 # define posix_spawn_file_actions_t rpl_posix_spawn_file_actions_t
96 #if @REPLACE_POSIX_SPAWN@ || !@HAVE_POSIX_SPAWN_FILE_ACTIONS_T@
101 struct __spawn_action *_actions;
103 } posix_spawn_file_actions_t;
107 /* Flags to be set in the `posix_spawnattr_t'. */
108 #if @REPLACE_POSIX_SPAWN@
109 /* Use the values from the system, for better compatibility. */
110 /* But this implementation does not support AIX extensions. */
111 # undef POSIX_SPAWN_FORK_HANDLERS
113 # define POSIX_SPAWN_RESETIDS 0x01
114 # define POSIX_SPAWN_SETPGROUP 0x02
115 # define POSIX_SPAWN_SETSIGDEF 0x04
116 # define POSIX_SPAWN_SETSIGMASK 0x08
117 # define POSIX_SPAWN_SETSCHEDPARAM 0x10
118 # define POSIX_SPAWN_SETSCHEDULER 0x20
120 /* A GNU extension. Use the next free bit position. */
121 #define POSIX_SPAWN_USEVFORK \
122 ((POSIX_SPAWN_RESETIDS | (POSIX_SPAWN_RESETIDS - 1) \
123 | POSIX_SPAWN_SETPGROUP | (POSIX_SPAWN_SETPGROUP - 1) \
124 | POSIX_SPAWN_SETSIGDEF | (POSIX_SPAWN_SETSIGDEF - 1) \
125 | POSIX_SPAWN_SETSIGMASK | (POSIX_SPAWN_SETSIGMASK - 1) \
126 | POSIX_SPAWN_SETSCHEDPARAM | (POSIX_SPAWN_SETSCHEDPARAM - 1) \
127 | POSIX_SPAWN_SETSCHEDULER | (POSIX_SPAWN_SETSCHEDULER - 1)) \
129 typedef int verify_POSIX_SPAWN_USEVFORK_no_overlap
130 [2 * (((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP
131 | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK
132 | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)
133 & POSIX_SPAWN_USEVFORK) == 0) - 1];
141 #if @GNULIB_POSIX_SPAWN@
142 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
143 Before running the process perform the actions described in FILE-ACTIONS.
145 This function is a possible cancellation points and therefore not
146 marked with __THROW. */
147 # if @REPLACE_POSIX_SPAWN@
148 # define posix_spawn rpl_posix_spawn
150 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
151 extern int posix_spawn (pid_t *_Restrict_ __pid,
152 const char *_Restrict_ __path,
153 const posix_spawn_file_actions_t *_Restrict_ __file_actions,
154 const posix_spawnattr_t *_Restrict_ __attrp,
155 char *const argv[_Restrict_arr_],
156 char *const envp[_Restrict_arr_])
157 _GL_ARG_NONNULL ((2, 5, 6));
161 #if @GNULIB_POSIX_SPAWNP@
162 /* Similar to `posix_spawn' but search for FILE in the PATH.
164 This function is a possible cancellation points and therefore not
165 marked with __THROW. */
166 # if @REPLACE_POSIX_SPAWN@
167 # define posix_spawnp rpl_posix_spawnp
169 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
170 extern int posix_spawnp (pid_t *__pid, const char *__file,
171 const posix_spawn_file_actions_t *__file_actions,
172 const posix_spawnattr_t *__attrp,
173 char *const argv[], char *const envp[])
174 _GL_ARG_NONNULL ((2, 5, 6));
179 #if @GNULIB_POSIX_SPAWNATTR_INIT@
180 /* Initialize data structure with attributes for `spawn' to default values. */
181 # if @REPLACE_POSIX_SPAWN@
182 # define posix_spawnattr_init rpl_posix_spawnattr_init
184 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
185 extern int posix_spawnattr_init (posix_spawnattr_t *__attr)
186 __THROW _GL_ARG_NONNULL ((1));
190 #if @GNULIB_POSIX_SPAWNATTR_DESTROY@
191 /* Free resources associated with ATTR. */
192 # if @REPLACE_POSIX_SPAWN@
193 # define posix_spawnattr_destroy rpl_posix_spawnattr_destroy
195 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
196 extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr)
197 __THROW _GL_ARG_NONNULL ((1));
201 #if @GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT@
202 /* Store signal mask for signals with default handling from ATTR in
204 # if @REPLACE_POSIX_SPAWN@
205 # define posix_spawnattr_getsigdefault rpl_posix_spawnattr_getsigdefault
207 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
208 extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *_Restrict_ __attr,
209 sigset_t *_Restrict_ __sigdefault)
210 __THROW _GL_ARG_NONNULL ((1, 2));
214 #if @GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT@
215 /* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */
216 # if @REPLACE_POSIX_SPAWN@
217 # define posix_spawnattr_setsigdefault rpl_posix_spawnattr_setsigdefault
219 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
220 extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *_Restrict_ __attr,
221 const sigset_t *_Restrict_ __sigdefault)
222 __THROW _GL_ARG_NONNULL ((1, 2));
226 #if @GNULIB_POSIX_SPAWNATTR_GETSIGMASK@
227 /* Store signal mask for the new process from ATTR in SIGMASK. */
228 # if @REPLACE_POSIX_SPAWN@
229 # define posix_spawnattr_getsigmask rpl_posix_spawnattr_getsigmask
231 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
232 extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *_Restrict_ __attr,
233 sigset_t *_Restrict_ __sigmask)
234 __THROW _GL_ARG_NONNULL ((1, 2));
238 #if @GNULIB_POSIX_SPAWNATTR_SETSIGMASK@
239 /* Set signal mask for the new process in ATTR to SIGMASK. */
240 # if @REPLACE_POSIX_SPAWN@
241 # define posix_spawnattr_setsigmask rpl_posix_spawnattr_setsigmask
243 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
244 extern int posix_spawnattr_setsigmask (posix_spawnattr_t *_Restrict_ __attr,
245 const sigset_t *_Restrict_ __sigmask)
246 __THROW _GL_ARG_NONNULL ((1, 2));
250 #if @GNULIB_POSIX_SPAWNATTR_GETFLAGS@
251 /* Get flag word from the attribute structure. */
252 # if @REPLACE_POSIX_SPAWN@
253 # define posix_spawnattr_getflags rpl_posix_spawnattr_getflags
255 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
256 extern int posix_spawnattr_getflags (const posix_spawnattr_t *_Restrict_ __attr,
257 short int *_Restrict_ __flags)
258 __THROW _GL_ARG_NONNULL ((1, 2));
262 #if @GNULIB_POSIX_SPAWNATTR_SETFLAGS@
263 /* Store flags in the attribute structure. */
264 # if @REPLACE_POSIX_SPAWN@
265 # define posix_spawnattr_setflags rpl_posix_spawnattr_setflags
267 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
268 extern int posix_spawnattr_setflags (posix_spawnattr_t *__attr,
270 __THROW _GL_ARG_NONNULL ((1));
274 #if @GNULIB_POSIX_SPAWNATTR_GETPGROUP@
275 /* Get process group ID from the attribute structure. */
276 # if @REPLACE_POSIX_SPAWN@
277 # define posix_spawnattr_getpgroup rpl_posix_spawnattr_getpgroup
279 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
280 extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *_Restrict_ __attr,
281 pid_t *_Restrict_ __pgroup)
282 __THROW _GL_ARG_NONNULL ((1, 2));
286 #if @GNULIB_POSIX_SPAWNATTR_SETPGROUP@
287 /* Store process group ID in the attribute structure. */
288 # if @REPLACE_POSIX_SPAWN@
289 # define posix_spawnattr_setpgroup rpl_posix_spawnattr_setpgroup
291 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
292 extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr,
294 __THROW _GL_ARG_NONNULL ((1));
298 #if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY@
299 /* Get scheduling policy from the attribute structure. */
300 # if @REPLACE_POSIX_SPAWN@
301 # define posix_spawnattr_getschedpolicy rpl_posix_spawnattr_getschedpolicy
303 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
304 extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *_Restrict_ __attr,
305 int *_Restrict_ __schedpolicy)
306 __THROW _GL_ARG_NONNULL ((1, 2));
310 #if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY@
311 /* Store scheduling policy in the attribute structure. */
312 # if @REPLACE_POSIX_SPAWN@
313 # define posix_spawnattr_setschedpolicy rpl_posix_spawnattr_setschedpolicy
315 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
316 extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr,
318 __THROW _GL_ARG_NONNULL ((1));
322 #if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM@
323 /* Get scheduling parameters from the attribute structure. */
324 # if @REPLACE_POSIX_SPAWN@
325 # define posix_spawnattr_getschedparam rpl_posix_spawnattr_getschedparam
327 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
328 extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *_Restrict_ __attr,
329 struct sched_param *_Restrict_ __schedparam)
330 __THROW _GL_ARG_NONNULL ((1, 2));
334 #if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM@
335 /* Store scheduling parameters in the attribute structure. */
336 # if @REPLACE_POSIX_SPAWN@
337 # define posix_spawnattr_setschedparam rpl_posix_spawnattr_setschedparam
339 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
340 extern int posix_spawnattr_setschedparam (posix_spawnattr_t *_Restrict_ __attr,
341 const struct sched_param *_Restrict_ __schedparam)
342 __THROW _GL_ARG_NONNULL ((1, 2));
347 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT@
348 /* Initialize data structure for file attribute for `spawn' call. */
349 # if @REPLACE_POSIX_SPAWN@
350 # define posix_spawn_file_actions_init rpl_posix_spawn_file_actions_init
352 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
353 extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t *__file_actions)
354 __THROW _GL_ARG_NONNULL ((1));
358 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY@
359 /* Free resources associated with FILE-ACTIONS. */
360 # if @REPLACE_POSIX_SPAWN@
361 # define posix_spawn_file_actions_destroy rpl_posix_spawn_file_actions_destroy
363 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
364 extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *__file_actions)
365 __THROW _GL_ARG_NONNULL ((1));
369 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@
370 /* Add an action to FILE-ACTIONS which tells the implementation to call
371 `open' for the given file during the `spawn' call. */
372 # if @REPLACE_POSIX_SPAWN@
373 # define posix_spawn_file_actions_addopen rpl_posix_spawn_file_actions_addopen
375 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
376 extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *_Restrict_ __file_actions,
378 const char *_Restrict_ __path,
379 int __oflag, mode_t __mode)
380 __THROW _GL_ARG_NONNULL ((1, 3));
384 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@
385 /* Add an action to FILE-ACTIONS which tells the implementation to call
386 `close' for the given file descriptor during the `spawn' call. */
387 # if @REPLACE_POSIX_SPAWN@
388 # define posix_spawn_file_actions_addclose rpl_posix_spawn_file_actions_addclose
390 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
391 extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *__file_actions,
393 __THROW _GL_ARG_NONNULL ((1));
397 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@
398 /* Add an action to FILE-ACTIONS which tells the implementation to call
399 `dup2' for the given file descriptors during the `spawn' call. */
400 # if @REPLACE_POSIX_SPAWN@
401 # define posix_spawn_file_actions_adddup2 rpl_posix_spawn_file_actions_adddup2
403 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
404 extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *__file_actions,
405 int __fd, int __newfd)
406 __THROW _GL_ARG_NONNULL ((1));
416 #endif /* _GL_SPAWN_H */
417 #endif /* _GL_SPAWN_H */