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