1 /* Definitions for POSIX spawn interface.
2 Copyright (C) 2000, 2003, 2004, 2008 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. */
71 /* Data structure to contain attributes for thread creation. */
72 #if @REPLACE_POSIX_SPAWN@
73 # define posix_spawnattr_t rpl_posix_spawnattr_t
81 struct sched_param _sp;
87 /* Data structure to contain information about the actions to be
88 performed in the new process with respect to file descriptors. */
89 #if @REPLACE_POSIX_SPAWN@
90 # define posix_spawn_file_actions_t rpl_posix_spawn_file_actions_t
96 struct __spawn_action *_actions;
98 } posix_spawn_file_actions_t;
101 /* Flags to be set in the `posix_spawnattr_t'. */
102 #if @REPLACE_POSIX_SPAWN@
103 /* Use the values from the system, for better compatibility. */
104 /* But this implementation does not support AIX extensions. */
105 # undef POSIX_SPAWN_FORK_HANDLERS
107 # define POSIX_SPAWN_RESETIDS 0x01
108 # define POSIX_SPAWN_SETPGROUP 0x02
109 # define POSIX_SPAWN_SETSIGDEF 0x04
110 # define POSIX_SPAWN_SETSIGMASK 0x08
111 # define POSIX_SPAWN_SETSCHEDPARAM 0x10
112 # define POSIX_SPAWN_SETSCHEDULER 0x20
114 /* A GNU extension. Use the next free bit position. */
115 #define POSIX_SPAWN_USEVFORK \
116 ((POSIX_SPAWN_RESETIDS | (POSIX_SPAWN_RESETIDS - 1) \
117 | POSIX_SPAWN_SETPGROUP | (POSIX_SPAWN_SETPGROUP - 1) \
118 | POSIX_SPAWN_SETSIGDEF | (POSIX_SPAWN_SETSIGDEF - 1) \
119 | POSIX_SPAWN_SETSIGMASK | (POSIX_SPAWN_SETSIGMASK - 1) \
120 | POSIX_SPAWN_SETSCHEDPARAM | (POSIX_SPAWN_SETSCHEDPARAM - 1) \
121 | POSIX_SPAWN_SETSCHEDULER | (POSIX_SPAWN_SETSCHEDULER - 1)) \
123 typedef int verify_POSIX_SPAWN_USEVFORK_no_overlap
124 [2 * (((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP
125 | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK
126 | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)
127 & POSIX_SPAWN_USEVFORK) == 0) - 1];
135 #if @GNULIB_POSIX_SPAWN@
136 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
137 Before running the process perform the actions described in FILE-ACTIONS.
139 This function is a possible cancellation points and therefore not
140 marked with __THROW. */
141 # if @REPLACE_POSIX_SPAWN@
142 # define posix_spawn rpl_posix_spawn
144 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
145 extern int posix_spawn (pid_t *_Restrict_ __pid,
146 const char *_Restrict_ __path,
147 const posix_spawn_file_actions_t *_Restrict_ __file_actions,
148 const posix_spawnattr_t *_Restrict_ __attrp,
149 char *const argv[_Restrict_arr_],
150 char *const envp[_Restrict_arr_]);
154 #if @GNULIB_POSIX_SPAWNP@
155 /* Similar to `posix_spawn' but search for FILE in the PATH.
157 This function is a possible cancellation points and therefore not
158 marked with __THROW. */
159 # if @REPLACE_POSIX_SPAWN@
160 # define posix_spawnp rpl_posix_spawnp
162 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
163 extern int posix_spawnp (pid_t *__pid, const char *__file,
164 const posix_spawn_file_actions_t *__file_actions,
165 const posix_spawnattr_t *__attrp,
166 char *const argv[], char *const envp[]);
171 #if @GNULIB_POSIX_SPAWNATTR_INIT@
172 /* Initialize data structure with attributes for `spawn' to default values. */
173 # if @REPLACE_POSIX_SPAWN@
174 # define posix_spawnattr_init rpl_posix_spawnattr_init
176 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
177 extern int posix_spawnattr_init (posix_spawnattr_t *__attr) __THROW;
181 #if @GNULIB_POSIX_SPAWNATTR_DESTROY@
182 /* Free resources associated with ATTR. */
183 # if @REPLACE_POSIX_SPAWN@
184 # define posix_spawnattr_destroy rpl_posix_spawnattr_destroy
186 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
187 extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr) __THROW;
191 #if @GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT@
192 /* Store signal mask for signals with default handling from ATTR in
194 # if @REPLACE_POSIX_SPAWN@
195 # define posix_spawnattr_getsigdefault rpl_posix_spawnattr_getsigdefault
197 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
198 extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *_Restrict_ __attr,
199 sigset_t *_Restrict_ __sigdefault)
204 #if @GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT@
205 /* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */
206 # if @REPLACE_POSIX_SPAWN@
207 # define posix_spawnattr_setsigdefault rpl_posix_spawnattr_setsigdefault
209 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
210 extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *_Restrict_ __attr,
211 const sigset_t *_Restrict_ __sigdefault)
216 #if @GNULIB_POSIX_SPAWNATTR_GETSIGMASK@
217 /* Store signal mask for the new process from ATTR in SIGMASK. */
218 # if @REPLACE_POSIX_SPAWN@
219 # define posix_spawnattr_getsigmask rpl_posix_spawnattr_getsigmask
221 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
222 extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *_Restrict_ __attr,
223 sigset_t *_Restrict_ __sigmask) __THROW;
227 #if @GNULIB_POSIX_SPAWNATTR_SETSIGMASK@
228 /* Set signal mask for the new process in ATTR to SIGMASK. */
229 # if @REPLACE_POSIX_SPAWN@
230 # define posix_spawnattr_setsigmask rpl_posix_spawnattr_setsigmask
232 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
233 extern int posix_spawnattr_setsigmask (posix_spawnattr_t *_Restrict_ __attr,
234 const sigset_t *_Restrict_ __sigmask)
239 #if @GNULIB_POSIX_SPAWNATTR_GETFLAGS@
240 /* Get flag word from the attribute structure. */
241 # if @REPLACE_POSIX_SPAWN@
242 # define posix_spawnattr_getflags rpl_posix_spawnattr_getflags
244 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
245 extern int posix_spawnattr_getflags (const posix_spawnattr_t *_Restrict_ __attr,
246 short int *_Restrict_ __flags) __THROW;
250 #if @GNULIB_POSIX_SPAWNATTR_SETFLAGS@
251 /* Store flags in the attribute structure. */
252 # if @REPLACE_POSIX_SPAWN@
253 # define posix_spawnattr_setflags rpl_posix_spawnattr_setflags
255 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
256 extern int posix_spawnattr_setflags (posix_spawnattr_t *__attr,
257 short int __flags) __THROW;
261 #if @GNULIB_POSIX_SPAWNATTR_GETPGROUP@
262 /* Get process group ID from the attribute structure. */
263 # if @REPLACE_POSIX_SPAWN@
264 # define posix_spawnattr_getpgroup rpl_posix_spawnattr_getpgroup
266 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
267 extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *_Restrict_ __attr,
268 pid_t *_Restrict_ __pgroup)
273 #if @GNULIB_POSIX_SPAWNATTR_SETPGROUP@
274 /* Store process group ID in the attribute structure. */
275 # if @REPLACE_POSIX_SPAWN@
276 # define posix_spawnattr_setpgroup rpl_posix_spawnattr_setpgroup
278 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
279 extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr,
280 pid_t __pgroup) __THROW;
284 #if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY@
285 /* Get scheduling policy from the attribute structure. */
286 # if @REPLACE_POSIX_SPAWN@
287 # define posix_spawnattr_getschedpolicy rpl_posix_spawnattr_getschedpolicy
289 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
290 extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *_Restrict_ __attr,
291 int *_Restrict_ __schedpolicy)
296 #if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY@
297 /* Store scheduling policy in the attribute structure. */
298 # if @REPLACE_POSIX_SPAWN@
299 # define posix_spawnattr_setschedpolicy rpl_posix_spawnattr_setschedpolicy
301 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
302 extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr,
303 int __schedpolicy) __THROW;
307 #if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM@
308 /* Get scheduling parameters from the attribute structure. */
309 # if @REPLACE_POSIX_SPAWN@
310 # define posix_spawnattr_getschedparam rpl_posix_spawnattr_getschedparam
312 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
313 extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *_Restrict_ __attr,
314 struct sched_param *_Restrict_ __schedparam) __THROW;
318 #if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM@
319 /* Store scheduling parameters in the attribute structure. */
320 # if @REPLACE_POSIX_SPAWN@
321 # define posix_spawnattr_setschedparam rpl_posix_spawnattr_setschedparam
323 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
324 extern int posix_spawnattr_setschedparam (posix_spawnattr_t *_Restrict_ __attr,
325 const struct sched_param *_Restrict_ __schedparam) __THROW;
330 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT@
331 /* Initialize data structure for file attribute for `spawn' call. */
332 # if @REPLACE_POSIX_SPAWN@
333 # define posix_spawn_file_actions_init rpl_posix_spawn_file_actions_init
335 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
336 extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t *__file_actions) __THROW;
340 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY@
341 /* Free resources associated with FILE-ACTIONS. */
342 # if @REPLACE_POSIX_SPAWN@
343 # define posix_spawn_file_actions_destroy rpl_posix_spawn_file_actions_destroy
345 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
346 extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *__file_actions) __THROW;
350 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@
351 /* Add an action to FILE-ACTIONS which tells the implementation to call
352 `open' for the given file during the `spawn' call. */
353 # if @REPLACE_POSIX_SPAWN@
354 # define posix_spawn_file_actions_addopen rpl_posix_spawn_file_actions_addopen
356 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
357 extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *_Restrict_ __file_actions,
359 const char *_Restrict_ __path,
360 int __oflag, mode_t __mode)
365 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@
366 /* Add an action to FILE-ACTIONS which tells the implementation to call
367 `close' for the given file descriptor during the `spawn' call. */
368 # if @REPLACE_POSIX_SPAWN@
369 # define posix_spawn_file_actions_addclose rpl_posix_spawn_file_actions_addclose
371 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
372 extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *__file_actions,
378 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@
379 /* Add an action to FILE-ACTIONS which tells the implementation to call
380 `dup2' for the given file descriptors during the `spawn' call. */
381 # if @REPLACE_POSIX_SPAWN@
382 # define posix_spawn_file_actions_adddup2 rpl_posix_spawn_file_actions_adddup2
384 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
385 extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *__file_actions,
386 int __fd, int __newfd) __THROW;
396 #endif /* _GL_SPAWN_H */
397 #endif /* _GL_SPAWN_H */