]> git.ipfire.org Git - thirdparty/glibc.git/blame - posix/spawn.h
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / posix / spawn.h
CommitLineData
a5a6f926 1/* Definitions for POSIX spawn interface.
04277e02 2 Copyright (C) 2000-2019 Free Software Foundation, Inc.
a5a6f926
UD
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
41bdb6e2
AJ
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.
a5a6f926
UD
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
41bdb6e2 13 Lesser General Public License for more details.
a5a6f926 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
a5a6f926
UD
18
19#ifndef _SPAWN_H
20#define _SPAWN_H 1
21
22#include <features.h>
23#include <sched.h>
a5a6f926 24#include <sys/types.h>
a992f506 25#include <bits/types/sigset_t.h>
a5a6f926
UD
26
27
28/* Data structure to contain attributes for thread creation. */
29typedef 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. */
43typedef 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
9ad68422
UD
59#ifdef __USE_GNU
60# define POSIX_SPAWN_USEVFORK 0x40
daeb1fa2 61# define POSIX_SPAWN_SETSID 0x80
9ad68422 62#endif
a5a6f926
UD
63
64
65__BEGIN_DECLS
66
67/* Spawn a new process executing PATH with the attributes describes in *ATTRP.
2c008571
UD
68 Before running the process perform the actions described in FILE-ACTIONS.
69
4c1423ed 70 This function is a possible cancellation point and therefore not
2c008571 71 marked with __THROW. */
98cbe360 72extern int posix_spawn (pid_t *__restrict __pid,
a784e502
UD
73 const char *__restrict __path,
74 const posix_spawn_file_actions_t *__restrict
98cbe360 75 __file_actions,
a784e502
UD
76 const posix_spawnattr_t *__restrict __attrp,
77 char *const __argv[__restrict_arr],
2ab5741b
FW
78 char *const __envp[__restrict_arr])
79 __nonnull ((2, 5));
2c008571
UD
80
81/* Similar to `posix_spawn' but search for FILE in the PATH.
a5a6f926 82
4c1423ed 83 This function is a possible cancellation point and therefore not
2c008571 84 marked with __THROW. */
a784e502
UD
85extern int posix_spawnp (pid_t *__pid, const char *__file,
86 const posix_spawn_file_actions_t *__file_actions,
87 const posix_spawnattr_t *__attrp,
2ab5741b
FW
88 char *const __argv[], char *const __envp[])
89 __nonnull ((2, 5));
a5a6f926
UD
90
91
92/* Initialize data structure with attributes for `spawn' to default values. */
2ab5741b
FW
93extern int posix_spawnattr_init (posix_spawnattr_t *__attr)
94 __THROW __nonnull ((1));
a5a6f926
UD
95
96/* Free resources associated with ATTR. */
2ab5741b
FW
97extern int posix_spawnattr_destroy (posix_spawnattr_t *__attr)
98 __THROW __nonnull ((1));
a5a6f926
UD
99
100/* Store signal mask for signals with default handling from ATTR in
101 SIGDEFAULT. */
a784e502 102extern int posix_spawnattr_getsigdefault (const posix_spawnattr_t *
98cbe360
UD
103 __restrict __attr,
104 sigset_t *__restrict __sigdefault)
2ab5741b 105 __THROW __nonnull ((1, 2));
a5a6f926
UD
106
107/* Set signal mask for signals with default handling in ATTR to SIGDEFAULT. */
98cbe360 108extern int posix_spawnattr_setsigdefault (posix_spawnattr_t *__restrict __attr,
a784e502 109 const sigset_t *__restrict
98cbe360 110 __sigdefault)
2ab5741b 111 __THROW __nonnull ((1, 2));
a5a6f926
UD
112
113/* Store signal mask for the new process from ATTR in SIGMASK. */
a784e502 114extern int posix_spawnattr_getsigmask (const posix_spawnattr_t *__restrict
98cbe360 115 __attr,
2ab5741b
FW
116 sigset_t *__restrict __sigmask)
117 __THROW __nonnull ((1, 2));
a5a6f926
UD
118
119/* Set signal mask for the new process in ATTR to SIGMASK. */
98cbe360 120extern int posix_spawnattr_setsigmask (posix_spawnattr_t *__restrict __attr,
a784e502 121 const sigset_t *__restrict __sigmask)
2ab5741b 122 __THROW __nonnull ((1, 2));
a5a6f926
UD
123
124/* Get flag word from the attribute structure. */
a784e502 125extern int posix_spawnattr_getflags (const posix_spawnattr_t *__restrict
98cbe360 126 __attr,
2ab5741b
FW
127 short int *__restrict __flags)
128 __THROW __nonnull ((1, 2));
a5a6f926
UD
129
130/* Store flags in the attribute structure. */
131extern int posix_spawnattr_setflags (posix_spawnattr_t *_attr,
2ab5741b
FW
132 short int __flags)
133 __THROW __nonnull ((1));
a5a6f926
UD
134
135/* Get process group ID from the attribute structure. */
a784e502 136extern int posix_spawnattr_getpgroup (const posix_spawnattr_t *__restrict
98cbe360 137 __attr, pid_t *__restrict __pgroup)
2ab5741b 138 __THROW __nonnull ((1, 2));
a5a6f926
UD
139
140/* Store process group ID in the attribute structure. */
141extern int posix_spawnattr_setpgroup (posix_spawnattr_t *__attr,
2ab5741b
FW
142 pid_t __pgroup)
143 __THROW __nonnull ((1));
a5a6f926
UD
144
145/* Get scheduling policy from the attribute structure. */
a784e502 146extern int posix_spawnattr_getschedpolicy (const posix_spawnattr_t *
98cbe360
UD
147 __restrict __attr,
148 int *__restrict __schedpolicy)
2ab5741b 149 __THROW __nonnull ((1, 2));
a5a6f926
UD
150
151/* Store scheduling policy in the attribute structure. */
152extern int posix_spawnattr_setschedpolicy (posix_spawnattr_t *__attr,
2ab5741b
FW
153 int __schedpolicy)
154 __THROW __nonnull ((1));
a5a6f926 155
98cbe360 156/* Get scheduling parameters from the attribute structure. */
a784e502 157extern int posix_spawnattr_getschedparam (const posix_spawnattr_t *
98cbe360
UD
158 __restrict __attr,
159 struct sched_param *__restrict
2ab5741b
FW
160 __schedparam)
161 __THROW __nonnull ((1, 2));
98cbe360
UD
162
163/* Store scheduling parameters in the attribute structure. */
164extern int posix_spawnattr_setschedparam (posix_spawnattr_t *__restrict __attr,
165 const struct sched_param *
2ab5741b
FW
166 __restrict __schedparam)
167 __THROW __nonnull ((1, 2));
98cbe360 168
a5a6f926
UD
169
170/* Initialize data structure for file attribute for `spawn' call. */
171extern int posix_spawn_file_actions_init (posix_spawn_file_actions_t *
2ab5741b
FW
172 __file_actions)
173 __THROW __nonnull ((1));
a5a6f926
UD
174
175/* Free resources associated with FILE-ACTIONS. */
176extern int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *
2ab5741b
FW
177 __file_actions)
178 __THROW __nonnull ((1));
a5a6f926
UD
179
180/* Add an action to FILE-ACTIONS which tells the implementation to call
181 `open' for the given file during the `spawn' call. */
182extern int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *
98cbe360
UD
183 __restrict __file_actions,
184 int __fd,
a784e502 185 const char *__restrict __path,
a5a6f926 186 int __oflag, mode_t __mode)
2ab5741b 187 __THROW __nonnull ((1, 3));
a5a6f926
UD
188
189/* Add an action to FILE-ACTIONS which tells the implementation to call
190 `close' for the given file descriptor during the `spawn' call. */
191extern int posix_spawn_file_actions_addclose (posix_spawn_file_actions_t *
192 __file_actions, int __fd)
2ab5741b 193 __THROW __nonnull ((1));
a5a6f926
UD
194
195/* Add an action to FILE-ACTIONS which tells the implementation to call
196 `dup2' for the given file descriptors during the `spawn' call. */
197extern int posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *
198 __file_actions,
2ab5741b
FW
199 int __fd, int __newfd)
200 __THROW __nonnull ((1));
a5a6f926 201
4a938cb2
FW
202#ifdef __USE_GNU
203/* Add an action changing the directory to PATH during spawn. This
204 affects the subsequent file actions. */
2ab5741b
FW
205extern int posix_spawn_file_actions_addchdir_np (posix_spawn_file_actions_t *
206 __restrict __actions,
207 const char *__restrict __path)
208 __THROW __nonnull ((1, 2));
3a3fb755
FW
209
210/* Add an action changing the directory to FD during spawn. This
211 affects the subsequent file actions. FD is not duplicated and must
212 be open when the file action is executed. */
213extern int posix_spawn_file_actions_addfchdir_np (posix_spawn_file_actions_t *,
2ab5741b
FW
214 int __fd)
215 __THROW __nonnull ((1));
4a938cb2
FW
216#endif
217
a5a6f926
UD
218__END_DECLS
219
220#endif /* spawn.h */