Replace FSF snail mail address with URLs.
[platform/upstream/glibc.git] / posix / spawn.h
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.
4
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.
9
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.
14
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/>.  */
18
19 #ifndef _SPAWN_H
20 #define _SPAWN_H        1
21
22 #include <features.h>
23 #include <sched.h>
24 #include <signal.h>
25 #include <sys/types.h>
26
27
28 /* Data structure to contain attributes for thread creation.  */
29 typedef struct
30 {
31   short int __flags;
32   pid_t __pgrp;
33   sigset_t __sd;
34   sigset_t __ss;
35   struct sched_param __sp;
36   int __policy;
37   int __pad[16];
38 } posix_spawnattr_t;
39
40
41 /* Data structure to contain information about the actions to be
42    performed in the new process with respect to file descriptors.  */
43 typedef struct
44 {
45   int __allocated;
46   int __used;
47   struct __spawn_action *__actions;
48   int __pad[16];
49 } posix_spawn_file_actions_t;
50
51
52 /* Flags to be set in the `posix_spawnattr_t'.  */
53 #define POSIX_SPAWN_RESETIDS            0x01
54 #define POSIX_SPAWN_SETPGROUP           0x02
55 #define POSIX_SPAWN_SETSIGDEF           0x04
56 #define POSIX_SPAWN_SETSIGMASK          0x08
57 #define POSIX_SPAWN_SETSCHEDPARAM       0x10
58 #define POSIX_SPAWN_SETSCHEDULER        0x20
59 #ifdef __USE_GNU
60 # define POSIX_SPAWN_USEVFORK           0x40
61 #endif
62
63
64 __BEGIN_DECLS
65
66 /* Spawn a new process executing PATH with the attributes describes in *ATTRP.
67    Before running the process perform the actions described in FILE-ACTIONS.
68
69    This function is a possible cancellation point and therefore not
70    marked with __THROW. */
71 extern int posix_spawn (pid_t *__restrict __pid,
72                         const char *__restrict __path,
73                         const posix_spawn_file_actions_t *__restrict
74                         __file_actions,
75                         const posix_spawnattr_t *__restrict __attrp,
76                         char *const __argv[__restrict_arr],
77                         char *const __envp[__restrict_arr]);
78
79 /* Similar to `posix_spawn' but search for FILE in the PATH.
80
81    This function is a possible cancellation point and therefore not
82    marked with __THROW.  */
83 extern int posix_spawnp (pid_t *__pid, const char *__file,
84                          const posix_spawn_file_actions_t *__file_actions,
85                          const posix_spawnattr_t *__attrp,
86                          char *const __argv[], char *const __envp[]);
87
88
89 /* Initialize data structure with attributes for `spawn' to default values.  */
90 extern int posix_spawnattr_init (posix_spawnattr_t *__attr) __THROW;
91
92 /* Free resources associated with ATTR.  */
93 extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr) __THROW;
94
95 /* Store signal mask for signals with default handling from ATTR in
96    SIGDEFAULT.  */
97 extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *
98                                           __restrict __attr,
99                                           sigset_t *__restrict __sigdefault)
100      __THROW;
101
102 /* Set signal mask for signals with default handling in ATTR to SIGDEFAULT.  */
103 extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *__restrict __attr,
104                                           const sigset_t *__restrict
105                                           __sigdefault)
106      __THROW;
107
108 /* Store signal mask for the new process from ATTR in SIGMASK.  */
109 extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *__restrict
110                                        __attr,
111                                        sigset_t *__restrict __sigmask) __THROW;
112
113 /* Set signal mask for the new process in ATTR to SIGMASK.  */
114 extern int posix_spawnattr_setsigmask (posix_spawnattr_t *__restrict __attr,
115                                        const sigset_t *__restrict __sigmask)
116      __THROW;
117
118 /* Get flag word from the attribute structure.  */
119 extern int posix_spawnattr_getflags (const posix_spawnattr_t *__restrict
120                                      __attr,
121                                      short int *__restrict __flags) __THROW;
122
123 /* Store flags in the attribute structure.  */
124 extern int posix_spawnattr_setflags (posix_spawnattr_t *_attr,
125                                      short int __flags) __THROW;
126
127 /* Get process group ID from the attribute structure.  */
128 extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *__restrict
129                                       __attr, pid_t *__restrict __pgroup)
130      __THROW;
131
132 /* Store process group ID in the attribute structure.  */
133 extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr,
134                                       pid_t __pgroup) __THROW;
135
136 /* Get scheduling policy from the attribute structure.  */
137 extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *
138                                            __restrict __attr,
139                                            int *__restrict __schedpolicy)
140      __THROW;
141
142 /* Store scheduling policy in the attribute structure.  */
143 extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr,
144                                            int __schedpolicy) __THROW;
145
146 /* Get scheduling parameters from the attribute structure.  */
147 extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *
148                                           __restrict __attr,
149                                           struct sched_param *__restrict
150                                           __schedparam) __THROW;
151
152 /* Store scheduling parameters in the attribute structure.  */
153 extern int posix_spawnattr_setschedparam (posix_spawnattr_t *__restrict __attr,
154                                           const struct sched_param *
155                                           __restrict __schedparam) __THROW;
156
157
158 /* Initialize data structure for file attribute for `spawn' call.  */
159 extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t *
160                                           __file_actions) __THROW;
161
162 /* Free resources associated with FILE-ACTIONS.  */
163 extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *
164                                              __file_actions) __THROW;
165
166 /* Add an action to FILE-ACTIONS which tells the implementation to call
167    `open' for the given file during the `spawn' call.  */
168 extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *
169                                              __restrict __file_actions,
170                                              int __fd,
171                                              const char *__restrict __path,
172                                              int __oflag, mode_t __mode)
173      __THROW;
174
175 /* Add an action to FILE-ACTIONS which tells the implementation to call
176    `close' for the given file descriptor during the `spawn' call.  */
177 extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *
178                                               __file_actions, int __fd)
179      __THROW;
180
181 /* Add an action to FILE-ACTIONS which tells the implementation to call
182    `dup2' for the given file descriptors during the `spawn' call.  */
183 extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *
184                                              __file_actions,
185                                              int __fd, int __newfd) __THROW;
186
187 __END_DECLS
188
189 #endif /* spawn.h */