Use the system's values, rather than overriding them by ours.
[gnulib.git] / lib / spawn.in.h
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.
4
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.
9
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.
14
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/>.  */
17
18 #ifndef _GL_SPAWN_H
19
20 @PRAGMA_SYSTEM_HEADER@
21
22 /* The include_next requires a split double-inclusion guard.  */
23 #if @HAVE_SPAWN_H@
24 # @INCLUDE_NEXT@ @NEXT_SPAWN_H@
25 #endif
26
27 #ifndef _GL_SPAWN_H
28 #define _GL_SPAWN_H
29
30 #include <sched.h>
31 #include <signal.h>
32 #include <sys/types.h>
33
34 #ifndef __THROW
35 # define __THROW
36 #endif
37
38 /* GCC 2.95 and later have "__restrict"; C99 compilers have
39    "restrict", and "configure" may have defined "restrict".
40    Other compilers use __restrict, __restrict__, and _Restrict, and
41    'configure' might #define 'restrict' to those words, so pick a
42    different name.  */
43 #ifndef _Restrict_
44 # if 199901L <= __STDC_VERSION__
45 #  define _Restrict_ restrict
46 # elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
47 #  define _Restrict_ __restrict
48 # else
49 #  define _Restrict_
50 # endif
51 #endif
52 /* gcc 3.1 and up support the [restrict] syntax.  Don't trust
53    sys/cdefs.h's definition of __restrict_arr, though, as it
54    mishandles gcc -ansi -pedantic.  */
55 #ifndef _Restrict_arr_
56 # if ((199901L <= __STDC_VERSION__                                      \
57        || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__))     \
58            && !__STRICT_ANSI__))                                        \
59       && !defined __GNUG__)
60 #  define _Restrict_arr_ _Restrict_
61 # else
62 #  define _Restrict_arr_
63 # endif
64 #endif
65
66 /* The definition of GL_LINK_WARNING is copied here.  */
67
68
69 /* Data structure to contain attributes for thread creation.  */
70 #if @REPLACE_POSIX_SPAWN@
71 # define posix_spawnattr_t rpl_posix_spawnattr_t
72 #endif
73 typedef struct
74 {
75   short int _flags;
76   pid_t _pgrp;
77   sigset_t _sd;
78   sigset_t _ss;
79   struct sched_param _sp;
80   int _policy;
81   int __pad[16];
82 } posix_spawnattr_t;
83
84
85 /* Data structure to contain information about the actions to be
86    performed in the new process with respect to file descriptors.  */
87 #if @REPLACE_POSIX_SPAWN@
88 # define posix_spawn_file_actions_t rpl_posix_spawn_file_actions_t
89 #endif
90 typedef struct
91 {
92   int _allocated;
93   int _used;
94   struct __spawn_action *_actions;
95   int __pad[16];
96 } posix_spawn_file_actions_t;
97
98
99 /* Flags to be set in the `posix_spawnattr_t'.  */
100 #if @REPLACE_POSIX_SPAWN@
101 /* Use the values from the system, for better compatibility.  */
102 /* But this implementation does not support AIX extensions.  */
103 # undef POSIX_SPAWN_FORK_HANDLERS
104 #else
105 # define POSIX_SPAWN_RESETIDS           0x01
106 # define POSIX_SPAWN_SETPGROUP          0x02
107 # define POSIX_SPAWN_SETSIGDEF          0x04
108 # define POSIX_SPAWN_SETSIGMASK         0x08
109 # define POSIX_SPAWN_SETSCHEDPARAM      0x10
110 # define POSIX_SPAWN_SETSCHEDULER       0x20
111 #endif
112 /* A GNU extension.  Use the next free bit position.  */
113 #define POSIX_SPAWN_USEVFORK \
114   ((POSIX_SPAWN_RESETIDS | (POSIX_SPAWN_RESETIDS - 1)                   \
115     | POSIX_SPAWN_SETPGROUP | (POSIX_SPAWN_SETPGROUP - 1)               \
116     | POSIX_SPAWN_SETSIGDEF | (POSIX_SPAWN_SETSIGDEF - 1)               \
117     | POSIX_SPAWN_SETSIGMASK | (POSIX_SPAWN_SETSIGMASK - 1)             \
118     | POSIX_SPAWN_SETSCHEDPARAM | (POSIX_SPAWN_SETSCHEDPARAM - 1)       \
119     | POSIX_SPAWN_SETSCHEDULER | (POSIX_SPAWN_SETSCHEDULER - 1))        \
120    + 1)
121 typedef int verify_POSIX_SPAWN_USEVFORK_no_overlap
122             [2 * (((POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP
123                     | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK
124                     | POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)
125                    & POSIX_SPAWN_USEVFORK) == 0) - 1];
126
127
128 #ifdef __cplusplus
129 extern "C" {
130 #endif
131
132
133 #if @GNULIB_POSIX_SPAWN@
134 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
135    Before running the process perform the actions described in FILE-ACTIONS.
136
137    This function is a possible cancellation points and therefore not
138    marked with __THROW. */
139 # if @REPLACE_POSIX_SPAWN@
140 #  define posix_spawn rpl_posix_spawn
141 # endif
142 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
143 extern int posix_spawn (pid_t *_Restrict_ __pid,
144                         const char *_Restrict_ __path,
145                         const posix_spawn_file_actions_t *_Restrict_ __file_actions,
146                         const posix_spawnattr_t *_Restrict_ __attrp,
147                         char *const argv[_Restrict_arr_],
148                         char *const envp[_Restrict_arr_]);
149 # endif
150 #endif
151
152 #if @GNULIB_POSIX_SPAWNP@
153 /* Similar to `posix_spawn' but search for FILE in the PATH.
154
155    This function is a possible cancellation points and therefore not
156    marked with __THROW.  */
157 # if @REPLACE_POSIX_SPAWN@
158 #  define posix_spawnp rpl_posix_spawnp
159 # endif
160 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
161 extern int posix_spawnp (pid_t *__pid, const char *__file,
162                          const posix_spawn_file_actions_t *__file_actions,
163                          const posix_spawnattr_t *__attrp,
164                          char *const argv[], char *const envp[]);
165 # endif
166 #endif
167
168
169 #if @GNULIB_POSIX_SPAWNATTR_INIT@
170 /* Initialize data structure with attributes for `spawn' to default values.  */
171 # if @REPLACE_POSIX_SPAWN@
172 #  define posix_spawnattr_init rpl_posix_spawnattr_init
173 # endif
174 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
175 extern int posix_spawnattr_init (posix_spawnattr_t *__attr) __THROW;
176 # endif
177 #endif
178
179 #if @GNULIB_POSIX_SPAWNATTR_DESTROY@
180 /* Free resources associated with ATTR.  */
181 # if @REPLACE_POSIX_SPAWN@
182 #  define posix_spawnattr_destroy rpl_posix_spawnattr_destroy
183 # endif
184 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
185 extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr) __THROW;
186 # endif
187 #endif
188
189 #if @GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT@
190 /* Store signal mask for signals with default handling from ATTR in
191    SIGDEFAULT.  */
192 # if @REPLACE_POSIX_SPAWN@
193 #  define posix_spawnattr_getsigdefault rpl_posix_spawnattr_getsigdefault
194 # endif
195 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
196 extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *_Restrict_ __attr,
197                                           sigset_t *_Restrict_ __sigdefault)
198      __THROW;
199 # endif
200 #endif
201
202 #if @GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT@
203 /* Set signal mask for signals with default handling in ATTR to SIGDEFAULT.  */
204 # if @REPLACE_POSIX_SPAWN@
205 #  define posix_spawnattr_setsigdefault rpl_posix_spawnattr_setsigdefault
206 # endif
207 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
208 extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *_Restrict_ __attr,
209                                           const sigset_t *_Restrict_ __sigdefault)
210      __THROW;
211 # endif
212 #endif
213
214 #if @GNULIB_POSIX_SPAWNATTR_GETSIGMASK@
215 /* Store signal mask for the new process from ATTR in SIGMASK.  */
216 # if @REPLACE_POSIX_SPAWN@
217 #  define posix_spawnattr_getsigmask rpl_posix_spawnattr_getsigmask
218 # endif
219 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
220 extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *_Restrict_ __attr,
221                                        sigset_t *_Restrict_ __sigmask) __THROW;
222 # endif
223 #endif
224
225 #if @GNULIB_POSIX_SPAWNATTR_SETSIGMASK@
226 /* Set signal mask for the new process in ATTR to SIGMASK.  */
227 # if @REPLACE_POSIX_SPAWN@
228 #  define posix_spawnattr_setsigmask rpl_posix_spawnattr_setsigmask
229 # endif
230 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
231 extern int posix_spawnattr_setsigmask (posix_spawnattr_t *_Restrict_ __attr,
232                                        const sigset_t *_Restrict_ __sigmask)
233      __THROW;
234 # endif
235 #endif
236
237 #if @GNULIB_POSIX_SPAWNATTR_GETFLAGS@
238 /* Get flag word from the attribute structure.  */
239 # if @REPLACE_POSIX_SPAWN@
240 #  define posix_spawnattr_getflags rpl_posix_spawnattr_getflags
241 # endif
242 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
243 extern int posix_spawnattr_getflags (const posix_spawnattr_t *_Restrict_ __attr,
244                                      short int *_Restrict_ __flags) __THROW;
245 # endif
246 #endif
247
248 #if @GNULIB_POSIX_SPAWNATTR_SETFLAGS@
249 /* Store flags in the attribute structure.  */
250 # if @REPLACE_POSIX_SPAWN@
251 #  define posix_spawnattr_setflags rpl_posix_spawnattr_setflags
252 # endif
253 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
254 extern int posix_spawnattr_setflags (posix_spawnattr_t *__attr,
255                                      short int __flags) __THROW;
256 # endif
257 #endif
258
259 #if @GNULIB_POSIX_SPAWNATTR_GETPGROUP@
260 /* Get process group ID from the attribute structure.  */
261 # if @REPLACE_POSIX_SPAWN@
262 #  define posix_spawnattr_getpgroup rpl_posix_spawnattr_getpgroup
263 # endif
264 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
265 extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *_Restrict_ __attr,
266                                       pid_t *_Restrict_ __pgroup)
267      __THROW;
268 # endif
269 #endif
270
271 #if @GNULIB_POSIX_SPAWNATTR_SETPGROUP@
272 /* Store process group ID in the attribute structure.  */
273 # if @REPLACE_POSIX_SPAWN@
274 #  define posix_spawnattr_setpgroup rpl_posix_spawnattr_setpgroup
275 # endif
276 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
277 extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr,
278                                       pid_t __pgroup) __THROW;
279 # endif
280 #endif
281
282 #if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY@
283 /* Get scheduling policy from the attribute structure.  */
284 # if @REPLACE_POSIX_SPAWN@
285 #  define posix_spawnattr_getschedpolicy rpl_posix_spawnattr_getschedpolicy
286 # endif
287 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
288 extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *_Restrict_ __attr,
289                                            int *_Restrict_ __schedpolicy)
290      __THROW;
291 # endif
292 #endif
293
294 #if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY@
295 /* Store scheduling policy in the attribute structure.  */
296 # if @REPLACE_POSIX_SPAWN@
297 #  define posix_spawnattr_setschedpolicy rpl_posix_spawnattr_setschedpolicy
298 # endif
299 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
300 extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr,
301                                            int __schedpolicy) __THROW;
302 # endif
303 #endif
304
305 #if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM@
306 /* Get scheduling parameters from the attribute structure.  */
307 # if @REPLACE_POSIX_SPAWN@
308 #  define posix_spawnattr_getschedparam rpl_posix_spawnattr_getschedparam
309 # endif
310 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
311 extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *_Restrict_ __attr,
312                                           struct sched_param *_Restrict_ __schedparam) __THROW;
313 # endif
314 #endif
315
316 #if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM@
317 /* Store scheduling parameters in the attribute structure.  */
318 # if @REPLACE_POSIX_SPAWN@
319 #  define posix_spawnattr_setschedparam rpl_posix_spawnattr_setschedparam
320 # endif
321 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
322 extern int posix_spawnattr_setschedparam (posix_spawnattr_t *_Restrict_ __attr,
323                                           const struct sched_param *_Restrict_ __schedparam) __THROW;
324 # endif
325 #endif
326
327
328 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT@
329 /* Initialize data structure for file attribute for `spawn' call.  */
330 # if @REPLACE_POSIX_SPAWN@
331 #  define posix_spawn_file_actions_init rpl_posix_spawn_file_actions_init
332 # endif
333 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
334 extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t *__file_actions) __THROW;
335 # endif
336 #endif
337
338 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY@
339 /* Free resources associated with FILE-ACTIONS.  */
340 # if @REPLACE_POSIX_SPAWN@
341 #  define posix_spawn_file_actions_destroy rpl_posix_spawn_file_actions_destroy
342 # endif
343 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
344 extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *__file_actions) __THROW;
345 # endif
346 #endif
347
348 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@
349 /* Add an action to FILE-ACTIONS which tells the implementation to call
350    `open' for the given file during the `spawn' call.  */
351 # if @REPLACE_POSIX_SPAWN@
352 #  define posix_spawn_file_actions_addopen rpl_posix_spawn_file_actions_addopen
353 # endif
354 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
355 extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *_Restrict_ __file_actions,
356                                              int __fd,
357                                              const char *_Restrict_ __path,
358                                              int __oflag, mode_t __mode)
359      __THROW;
360 # endif
361 #endif
362
363 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@
364 /* Add an action to FILE-ACTIONS which tells the implementation to call
365    `close' for the given file descriptor during the `spawn' call.  */
366 # if @REPLACE_POSIX_SPAWN@
367 #  define posix_spawn_file_actions_addclose rpl_posix_spawn_file_actions_addclose
368 # endif
369 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
370 extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *__file_actions,
371                                               int __fd)
372      __THROW;
373 # endif
374 #endif
375
376 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@
377 /* Add an action to FILE-ACTIONS which tells the implementation to call
378    `dup2' for the given file descriptors during the `spawn' call.  */
379 # if @REPLACE_POSIX_SPAWN@
380 #  define posix_spawn_file_actions_adddup2 rpl_posix_spawn_file_actions_adddup2
381 # endif
382 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
383 extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *__file_actions,
384                                              int __fd, int __newfd) __THROW;
385 # endif
386 #endif
387
388
389 #ifdef __cplusplus
390 }
391 #endif
392
393
394 #endif /* _GL_SPAWN_H */
395 #endif /* _GL_SPAWN_H */