New module 'spawn'.
[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 #define POSIX_SPAWN_RESETIDS            0x01
101 #define POSIX_SPAWN_SETPGROUP           0x02
102 #define POSIX_SPAWN_SETSIGDEF           0x04
103 #define POSIX_SPAWN_SETSIGMASK          0x08
104 #define POSIX_SPAWN_SETSCHEDPARAM       0x10
105 #define POSIX_SPAWN_SETSCHEDULER        0x20
106 /* A GNU extension.  */
107 #define POSIX_SPAWN_USEVFORK            0x40
108
109
110 #ifdef __cplusplus
111 extern "C" {
112 #endif
113
114
115 #if @GNULIB_POSIX_SPAWN@
116 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
117    Before running the process perform the actions described in FILE-ACTIONS.
118
119    This function is a possible cancellation points and therefore not
120    marked with __THROW. */
121 # if @REPLACE_POSIX_SPAWN@
122 #  define posix_spawn rpl_posix_spawn
123 # endif
124 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
125 extern int posix_spawn (pid_t *_Restrict_ __pid,
126                         const char *_Restrict_ __path,
127                         const posix_spawn_file_actions_t *_Restrict_ __file_actions,
128                         const posix_spawnattr_t *_Restrict_ __attrp,
129                         char *const argv[_Restrict_arr_],
130                         char *const envp[_Restrict_arr_]);
131 # endif
132 #endif
133
134 #if @GNULIB_POSIX_SPAWNP@
135 /* Similar to `posix_spawn' but search for FILE in the PATH.
136
137    This function is a possible cancellation points and therefore not
138    marked with __THROW.  */
139 # if @REPLACE_POSIX_SPAWN@
140 #  define posix_spawnp rpl_posix_spawnp
141 # endif
142 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
143 extern int posix_spawnp (pid_t *__pid, const char *__file,
144                          const posix_spawn_file_actions_t *__file_actions,
145                          const posix_spawnattr_t *__attrp,
146                          char *const argv[], char *const envp[]);
147 # endif
148 #endif
149
150
151 #if @GNULIB_POSIX_SPAWNATTR_INIT@
152 /* Initialize data structure with attributes for `spawn' to default values.  */
153 # if @REPLACE_POSIX_SPAWN@
154 #  define posix_spawnattr_init rpl_posix_spawnattr_init
155 # endif
156 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
157 extern int posix_spawnattr_init (posix_spawnattr_t *__attr) __THROW;
158 # endif
159 #endif
160
161 #if @GNULIB_POSIX_SPAWNATTR_DESTROY@
162 /* Free resources associated with ATTR.  */
163 # if @REPLACE_POSIX_SPAWN@
164 #  define posix_spawnattr_destroy rpl_posix_spawnattr_destroy
165 # endif
166 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
167 extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr) __THROW;
168 # endif
169 #endif
170
171 #if @GNULIB_POSIX_SPAWNATTR_GETSIGDEFAULT@
172 /* Store signal mask for signals with default handling from ATTR in
173    SIGDEFAULT.  */
174 # if @REPLACE_POSIX_SPAWN@
175 #  define posix_spawnattr_getsigdefault rpl_posix_spawnattr_getsigdefault
176 # endif
177 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
178 extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *_Restrict_ __attr,
179                                           sigset_t *_Restrict_ __sigdefault)
180      __THROW;
181 # endif
182 #endif
183
184 #if @GNULIB_POSIX_SPAWNATTR_SETSIGDEFAULT@
185 /* Set signal mask for signals with default handling in ATTR to SIGDEFAULT.  */
186 # if @REPLACE_POSIX_SPAWN@
187 #  define posix_spawnattr_setsigdefault rpl_posix_spawnattr_setsigdefault
188 # endif
189 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
190 extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *_Restrict_ __attr,
191                                           const sigset_t *_Restrict_ __sigdefault)
192      __THROW;
193 # endif
194 #endif
195
196 #if @GNULIB_POSIX_SPAWNATTR_GETSIGMASK@
197 /* Store signal mask for the new process from ATTR in SIGMASK.  */
198 # if @REPLACE_POSIX_SPAWN@
199 #  define posix_spawnattr_getsigmask rpl_posix_spawnattr_getsigmask
200 # endif
201 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
202 extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *_Restrict_ __attr,
203                                        sigset_t *_Restrict_ __sigmask) __THROW;
204 # endif
205 #endif
206
207 #if @GNULIB_POSIX_SPAWNATTR_SETSIGMASK@
208 /* Set signal mask for the new process in ATTR to SIGMASK.  */
209 # if @REPLACE_POSIX_SPAWN@
210 #  define posix_spawnattr_setsigmask rpl_posix_spawnattr_setsigmask
211 # endif
212 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
213 extern int posix_spawnattr_setsigmask (posix_spawnattr_t *_Restrict_ __attr,
214                                        const sigset_t *_Restrict_ __sigmask)
215      __THROW;
216 # endif
217 #endif
218
219 #if @GNULIB_POSIX_SPAWNATTR_GETFLAGS@
220 /* Get flag word from the attribute structure.  */
221 # if @REPLACE_POSIX_SPAWN@
222 #  define posix_spawnattr_getflags rpl_posix_spawnattr_getflags
223 # endif
224 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
225 extern int posix_spawnattr_getflags (const posix_spawnattr_t *_Restrict_ __attr,
226                                      short int *_Restrict_ __flags) __THROW;
227 # endif
228 #endif
229
230 #if @GNULIB_POSIX_SPAWNATTR_SETFLAGS@
231 /* Store flags in the attribute structure.  */
232 # if @REPLACE_POSIX_SPAWN@
233 #  define posix_spawnattr_setflags rpl_posix_spawnattr_setflags
234 # endif
235 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
236 extern int posix_spawnattr_setflags (posix_spawnattr_t *__attr,
237                                      short int __flags) __THROW;
238 # endif
239 #endif
240
241 #if @GNULIB_POSIX_SPAWNATTR_GETPGROUP@
242 /* Get process group ID from the attribute structure.  */
243 # if @REPLACE_POSIX_SPAWN@
244 #  define posix_spawnattr_getpgroup rpl_posix_spawnattr_getpgroup
245 # endif
246 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
247 extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *_Restrict_ __attr,
248                                       pid_t *_Restrict_ __pgroup)
249      __THROW;
250 # endif
251 #endif
252
253 #if @GNULIB_POSIX_SPAWNATTR_SETPGROUP@
254 /* Store process group ID in the attribute structure.  */
255 # if @REPLACE_POSIX_SPAWN@
256 #  define posix_spawnattr_setpgroup rpl_posix_spawnattr_setpgroup
257 # endif
258 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
259 extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr,
260                                       pid_t __pgroup) __THROW;
261 # endif
262 #endif
263
264 #if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPOLICY@
265 /* Get scheduling policy from the attribute structure.  */
266 # if @REPLACE_POSIX_SPAWN@
267 #  define posix_spawnattr_getschedpolicy rpl_posix_spawnattr_getschedpolicy
268 # endif
269 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
270 extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *_Restrict_ __attr,
271                                            int *_Restrict_ __schedpolicy)
272      __THROW;
273 # endif
274 #endif
275
276 #if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPOLICY@
277 /* Store scheduling policy in the attribute structure.  */
278 # if @REPLACE_POSIX_SPAWN@
279 #  define posix_spawnattr_setschedpolicy rpl_posix_spawnattr_setschedpolicy
280 # endif
281 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
282 extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr,
283                                            int __schedpolicy) __THROW;
284 # endif
285 #endif
286
287 #if @GNULIB_POSIX_SPAWNATTR_GETSCHEDPARAM@
288 /* Get scheduling parameters from the attribute structure.  */
289 # if @REPLACE_POSIX_SPAWN@
290 #  define posix_spawnattr_getschedparam rpl_posix_spawnattr_getschedparam
291 # endif
292 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
293 extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *_Restrict_ __attr,
294                                           struct sched_param *_Restrict_ __schedparam) __THROW;
295 # endif
296 #endif
297
298 #if @GNULIB_POSIX_SPAWNATTR_SETSCHEDPARAM@
299 /* Store scheduling parameters in the attribute structure.  */
300 # if @REPLACE_POSIX_SPAWN@
301 #  define posix_spawnattr_setschedparam rpl_posix_spawnattr_setschedparam
302 # endif
303 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
304 extern int posix_spawnattr_setschedparam (posix_spawnattr_t *_Restrict_ __attr,
305                                           const struct sched_param *_Restrict_ __schedparam) __THROW;
306 # endif
307 #endif
308
309
310 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_INIT@
311 /* Initialize data structure for file attribute for `spawn' call.  */
312 # if @REPLACE_POSIX_SPAWN@
313 #  define posix_spawn_file_actions_init rpl_posix_spawn_file_actions_init
314 # endif
315 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
316 extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t *__file_actions) __THROW;
317 # endif
318 #endif
319
320 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_DESTROY@
321 /* Free resources associated with FILE-ACTIONS.  */
322 # if @REPLACE_POSIX_SPAWN@
323 #  define posix_spawn_file_actions_destroy rpl_posix_spawn_file_actions_destroy
324 # endif
325 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
326 extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *__file_actions) __THROW;
327 # endif
328 #endif
329
330 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN@
331 /* Add an action to FILE-ACTIONS which tells the implementation to call
332    `open' for the given file during the `spawn' call.  */
333 # if @REPLACE_POSIX_SPAWN@
334 #  define posix_spawn_file_actions_addopen rpl_posix_spawn_file_actions_addopen
335 # endif
336 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
337 extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *_Restrict_ __file_actions,
338                                              int __fd,
339                                              const char *_Restrict_ __path,
340                                              int __oflag, mode_t __mode)
341      __THROW;
342 # endif
343 #endif
344
345 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE@
346 /* Add an action to FILE-ACTIONS which tells the implementation to call
347    `close' for the given file descriptor during the `spawn' call.  */
348 # if @REPLACE_POSIX_SPAWN@
349 #  define posix_spawn_file_actions_addclose rpl_posix_spawn_file_actions_addclose
350 # endif
351 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
352 extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *__file_actions,
353                                               int __fd)
354      __THROW;
355 # endif
356 #endif
357
358 #if @GNULIB_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2@
359 /* Add an action to FILE-ACTIONS which tells the implementation to call
360    `dup2' for the given file descriptors during the `spawn' call.  */
361 # if @REPLACE_POSIX_SPAWN@
362 #  define posix_spawn_file_actions_adddup2 rpl_posix_spawn_file_actions_adddup2
363 # endif
364 # if !@HAVE_POSIX_SPAWN@ || @REPLACE_POSIX_SPAWN@
365 extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *__file_actions,
366                                              int __fd, int __newfd) __THROW;
367 # endif
368 #endif
369
370
371 #ifdef __cplusplus
372 }
373 #endif
374
375
376 #endif /* _GL_SPAWN_H */
377 #endif /* _GL_SPAWN_H */