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
70 #define __POSIX_SPAWN_MASK (POSIX_SPAWN_RESETIDS \
71 | POSIX_SPAWN_SETPGROUP \
72 | POSIX_SPAWN_SETSIGDEF \
73 | POSIX_SPAWN_SETSIGMASK \
74 | POSIX_SPAWN_SETSCHEDPARAM \
75 | POSIX_SPAWN_SETSCHEDULER \
76 | POSIX_SPAWN_USEVFORK)
80 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
81 Before running the process perform the actions described in FILE-ACTIONS.
83 This function is a possible cancellation point and therefore not
84 marked with __THROW. */
85 extern int posix_spawn (pid_t *__restrict __pid,
86 const char *__restrict __path,
87 const posix_spawn_file_actions_t *__restrict
89 const posix_spawnattr_t *__restrict __attrp,
90 char *const __argv[__restrict_arr],
91 char *const __envp[__restrict_arr]);
93 /* Similar to `posix_spawn' but search for FILE in the PATH.
95 This function is a possible cancellation point and therefore not
96 marked with __THROW. */
97 extern int posix_spawnp (pid_t *__pid, const char *__file,
98 const posix_spawn_file_actions_t *__file_actions,
99 const posix_spawnattr_t *__attrp,
100 char *const __argv[], char *const __envp[]);
103 /* Initialize data structure with attributes for `spawn' to default values. */
105 int posix_spawnattr_init (posix_spawnattr_t *__attr)
107 memset (__attr, 0, sizeof (*__attr));
111 /* Free resources associated with ATTR. */
113 int posix_spawnattr_destroy (posix_spawnattr_t *__attr)
118 /* Store signal mask for signals with default handling from ATTR in
121 int posix_spawnattr_getsigdefault (const posix_spawnattr_t *
123 sigset_t *__restrict __sigdefault)
125 memcpy (__sigdefault, &__attr->__sd, sizeof (sigset_t));
129 /* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */
131 int posix_spawnattr_setsigdefault (posix_spawnattr_t *__restrict __attr,
132 const sigset_t *__restrict
135 memcpy (&__attr->__sd, __sigdefault, sizeof (sigset_t));
139 /* Store signal mask for the new process from ATTR in SIGMASK. */
141 int posix_spawnattr_getsigmask (const posix_spawnattr_t *__restrict
143 sigset_t *__restrict __sigmask)
145 memcpy (__sigmask, &__attr->__ss, sizeof (sigset_t));
149 /* Set signal mask for the new process in ATTR to SIGMASK. */
151 int posix_spawnattr_setsigmask (posix_spawnattr_t *__restrict __attr,
152 const sigset_t *__restrict __sigmask)
154 memcpy (&__attr->__ss, __sigmask, sizeof (sigset_t));
158 /* Get flag word from the attribute structure. */
160 int posix_spawnattr_getflags (const posix_spawnattr_t *__restrict
162 short int *__restrict __flags)
164 *__flags = __attr->__flags;
168 /* Store flags in the attribute structure. */
170 int posix_spawnattr_setflags (posix_spawnattr_t *_attr,
173 /* Check no invalid bits are set. */
174 if (__flags & ~__POSIX_SPAWN_MASK)
177 _attr->__flags = __flags;
181 /* Get process group ID from the attribute structure. */
183 int posix_spawnattr_getpgroup (const posix_spawnattr_t *__restrict
184 __attr, pid_t *__restrict __pgroup)
186 *__pgroup = __attr->__pgrp;
190 /* Store process group ID in the attribute structure. */
192 int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr,
195 __attr->__pgrp = __pgroup;
199 /* Get scheduling policy from the attribute structure. */
201 int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *
203 int *__restrict __schedpolicy)
205 *__schedpolicy = __attr->__policy;
209 /* Store scheduling policy in the attribute structure. */
211 int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr,
214 switch (__schedpolicy) {
223 __attr->__policy = __schedpolicy;
227 /* Get scheduling parameters from the attribute structure. */
229 int posix_spawnattr_getschedparam (const posix_spawnattr_t *
231 struct sched_param *__restrict
234 memcpy (__schedparam, &__attr->__sp, sizeof (__attr->__sp));
238 /* Store scheduling parameters in the attribute structure. */
240 int posix_spawnattr_setschedparam (posix_spawnattr_t *__restrict __attr,
241 const struct sched_param *
242 __restrict __schedparam)
244 __attr->__sp = *__schedparam;
248 /* Initialize data structure for file attribute for `spawn' call. */
250 int posix_spawn_file_actions_init (posix_spawn_file_actions_t *
253 memset (__file_actions, 0, sizeof (*__file_actions));
257 /* Free resources associated with FILE-ACTIONS. */
259 int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *
262 free (__file_actions->__actions);
266 /* Add an action to FILE-ACTIONS which tells the implementation to call
267 `open' for the given file during the `spawn' call. */
268 extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *
269 __restrict __file_actions,
271 const char *__restrict __path,
272 int __oflag, mode_t __mode)
275 /* Add an action to FILE-ACTIONS which tells the implementation to call
276 `close' for the given file descriptor during the `spawn' call. */
277 extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *
278 __file_actions, int __fd)
281 /* Add an action to FILE-ACTIONS which tells the implementation to call
282 `dup2' for the given file descriptors during the `spawn' call. */
283 extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *
285 int __fd, int __newfd) __THROW;