1 /* Definitions for POSIX spawn interface.
2 Copyright (C) 2000,2003,2004,2009,2011,2012 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
24 #define __need_sigset_t
26 #include <sys/types.h>
28 /* For the tiny inlines (errno/free/memset). */
34 /* Data structure to contain attributes for thread creation. */
41 struct sched_param __sp
;
47 /* Data structure to contain information about the actions to be
48 performed in the new process with respect to file descriptors. */
53 struct __spawn_action
*__actions
;
55 } posix_spawn_file_actions_t
;
58 /* Flags to be set in the `posix_spawnattr_t'. */
59 #define POSIX_SPAWN_RESETIDS 0x01
60 #define POSIX_SPAWN_SETPGROUP 0x02
61 #define POSIX_SPAWN_SETSIGDEF 0x04
62 #define POSIX_SPAWN_SETSIGMASK 0x08
63 #define POSIX_SPAWN_SETSCHEDPARAM 0x10
64 #define POSIX_SPAWN_SETSCHEDULER 0x20
66 # define POSIX_SPAWN_USEVFORK 0x40
71 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
72 Before running the process perform the actions described in FILE-ACTIONS.
74 This function is a possible cancellation point and therefore not
75 marked with __THROW. */
76 extern int posix_spawn (pid_t
*__restrict __pid
,
77 const char *__restrict __path
,
78 const posix_spawn_file_actions_t
*__restrict
80 const posix_spawnattr_t
*__restrict __attrp
,
81 char *const __argv
[__restrict_arr
],
82 char *const __envp
[__restrict_arr
]);
84 /* Similar to `posix_spawn' but search for FILE in the PATH.
86 This function is a possible cancellation point and therefore not
87 marked with __THROW. */
88 extern int posix_spawnp (pid_t
*__pid
, const char *__file
,
89 const posix_spawn_file_actions_t
*__file_actions
,
90 const posix_spawnattr_t
*__attrp
,
91 char *const __argv
[], char *const __envp
[]);
94 /* Initialize data structure with attributes for `spawn' to default values. */
96 int posix_spawnattr_init (posix_spawnattr_t
*__attr
)
98 memset (__attr
, 0, sizeof (*__attr
));
102 /* Free resources associated with ATTR. */
104 int posix_spawnattr_destroy (posix_spawnattr_t
*__attr
)
109 /* Store signal mask for signals with default handling from ATTR in
112 int posix_spawnattr_getsigdefault (const posix_spawnattr_t
*
114 sigset_t
*__restrict __sigdefault
)
116 memcpy (__sigdefault
, &__attr
->__sd
, sizeof (sigset_t
));
120 /* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */
122 int posix_spawnattr_setsigdefault (posix_spawnattr_t
*__restrict __attr
,
123 const sigset_t
*__restrict
126 memcpy (&__attr
->__sd
, __sigdefault
, sizeof (sigset_t
));
130 /* Store signal mask for the new process from ATTR in SIGMASK. */
132 int posix_spawnattr_getsigmask (const posix_spawnattr_t
*__restrict
134 sigset_t
*__restrict __sigmask
)
136 memcpy (__sigmask
, &__attr
->__ss
, sizeof (sigset_t
));
140 /* Set signal mask for the new process in ATTR to SIGMASK. */
142 int posix_spawnattr_setsigmask (posix_spawnattr_t
*__restrict __attr
,
143 const sigset_t
*__restrict __sigmask
)
145 memcpy (&__attr
->__ss
, __sigmask
, sizeof (sigset_t
));
149 /* Get flag word from the attribute structure. */
151 int posix_spawnattr_getflags (const posix_spawnattr_t
*__restrict
153 short int *__restrict __flags
)
155 *__flags
= __attr
->__flags
;
159 /* Store flags in the attribute structure. */
161 int posix_spawnattr_setflags (posix_spawnattr_t
*_attr
,
164 #ifdef POSIX_SPAWN_USEVFORK
165 # define __POSIX_SPAWN_USEVFORK POSIX_SPAWN_USEVFORK
167 # define __POSIX_SPAWN_USEVFORK 0
169 #define __POSIX_SPAWN_MASK (POSIX_SPAWN_RESETIDS \
170 | POSIX_SPAWN_SETPGROUP \
171 | POSIX_SPAWN_SETSIGDEF \
172 | POSIX_SPAWN_SETSIGMASK \
173 | POSIX_SPAWN_SETSCHEDPARAM \
174 | POSIX_SPAWN_SETSCHEDULER \
175 | __POSIX_SPAWN_USEVFORK)
177 /* Check no invalid bits are set. */
178 if (__flags
& ~__POSIX_SPAWN_MASK
)
181 _attr
->__flags
= __flags
;
183 #undef __POSIX_SPAWN_USEVFORK
184 #undef __POSIX_SPAWN_MASK
187 /* Get process group ID from the attribute structure. */
189 int posix_spawnattr_getpgroup (const posix_spawnattr_t
*__restrict
190 __attr
, pid_t
*__restrict __pgroup
)
192 *__pgroup
= __attr
->__pgrp
;
196 /* Store process group ID in the attribute structure. */
198 int posix_spawnattr_setpgroup (posix_spawnattr_t
*__attr
,
201 __attr
->__pgrp
= __pgroup
;
205 /* Get scheduling policy from the attribute structure. */
207 int posix_spawnattr_getschedpolicy (const posix_spawnattr_t
*
209 int *__restrict __schedpolicy
)
211 *__schedpolicy
= __attr
->__policy
;
215 /* Store scheduling policy in the attribute structure. */
217 int posix_spawnattr_setschedpolicy (posix_spawnattr_t
*__attr
,
220 switch (__schedpolicy
) {
229 __attr
->__policy
= __schedpolicy
;
233 /* Get scheduling parameters from the attribute structure. */
235 int posix_spawnattr_getschedparam (const posix_spawnattr_t
*
237 struct sched_param
*__restrict
240 memcpy (__schedparam
, &__attr
->__sp
, sizeof (__attr
->__sp
));
244 /* Store scheduling parameters in the attribute structure. */
246 int posix_spawnattr_setschedparam (posix_spawnattr_t
*__restrict __attr
,
247 const struct sched_param
*
248 __restrict __schedparam
)
250 __attr
->__sp
= *__schedparam
;
254 /* Initialize data structure for file attribute for `spawn' call. */
256 int posix_spawn_file_actions_init (posix_spawn_file_actions_t
*
259 memset (__file_actions
, 0, sizeof (*__file_actions
));
263 /* Free resources associated with FILE-ACTIONS. */
265 int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t
*
268 free (__file_actions
->__actions
);
272 /* Add an action to FILE-ACTIONS which tells the implementation to call
273 `open' for the given file during the `spawn' call. */
274 extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t
*
275 __restrict __file_actions
,
277 const char *__restrict __path
,
278 int __oflag
, mode_t __mode
)
281 /* Add an action to FILE-ACTIONS which tells the implementation to call
282 `close' for the given file descriptor during the `spawn' call. */
283 extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t
*
284 __file_actions
, int __fd
)
287 /* Add an action to FILE-ACTIONS which tells the implementation to call
288 `dup2' for the given file descriptors during the `spawn' call. */
289 extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t
*
291 int __fd
, int __newfd
) __THROW
;