xref: /illumos-gate/usr/src/head/spawn.h (revision 3114379f81d5ab88054ea9e72c8874984ea8c263)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24  *
25  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 /*
30  * Copyright (c) 2011 by Delphix. All rights reserved.
31  */
32 
33 #ifndef _SPAWN_H
34 #define	_SPAWN_H
35 
36 #include <sys/feature_tests.h>
37 #include <sys/types.h>
38 #include <signal.h>
39 #include <sched.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * flags for posix_spawnattr_setflags()
47  */
48 #define	POSIX_SPAWN_RESETIDS		0x0001
49 #define	POSIX_SPAWN_SETPGROUP		0x0002
50 #define	POSIX_SPAWN_SETSIGDEF		0x0004
51 #define	POSIX_SPAWN_SETSIGMASK		0x0008
52 #define	POSIX_SPAWN_SETSCHEDPARAM	0x0010
53 #define	POSIX_SPAWN_SETSCHEDULER	0x0020
54 #define	POSIX_SPAWN_SETSID		0x0040
55 /*
56  * non-portable extensions
57  */
58 #if !defined(_STRICT_POSIX)
59 #define	POSIX_SPAWN_SETSIGIGN_NP	0x0800
60 #define	POSIX_SPAWN_NOSIGCHLD_NP	0x1000
61 #define	POSIX_SPAWN_WAITPID_NP		0x2000
62 #define	POSIX_SPAWN_NOEXECERR_NP	0x4000
63 #endif	/* !_STRICT_POSIX */
64 
65 typedef struct {
66 	void *__spawn_attrp;	/* implementation-private */
67 } posix_spawnattr_t;
68 
69 typedef struct {
70 	void *__file_attrp;	/* implementation-private */
71 } posix_spawn_file_actions_t;
72 
73 extern int posix_spawn(
74 	pid_t *_RESTRICT_KYWD pid,
75 	const char *_RESTRICT_KYWD path,
76 	const posix_spawn_file_actions_t *file_actions,
77 	const posix_spawnattr_t *_RESTRICT_KYWD attrp,
78 	char *const *_RESTRICT_KYWD argv,
79 	char *const *_RESTRICT_KYWD envp);
80 
81 extern int posix_spawnp(
82 	pid_t *_RESTRICT_KYWD pid,
83 	const char *_RESTRICT_KYWD file,
84 	const posix_spawn_file_actions_t *file_actions,
85 	const posix_spawnattr_t *_RESTRICT_KYWD attrp,
86 	char *const *_RESTRICT_KYWD argv,
87 	char *const *_RESTRICT_KYWD envp);
88 
89 extern int posix_spawn_file_actions_init(
90 	posix_spawn_file_actions_t *file_actions);
91 
92 extern int posix_spawn_file_actions_destroy(
93 	posix_spawn_file_actions_t *file_actions);
94 
95 extern int posix_spawn_file_actions_addchdir(
96 	posix_spawn_file_actions_t *_RESTRICT_KYWD file_actions,
97 	const char *_RESTRICT_KYWD path);
98 
99 extern int posix_spawn_file_actions_addopen(
100 	posix_spawn_file_actions_t *_RESTRICT_KYWD file_actions,
101 	int filedes,
102 	const char *_RESTRICT_KYWD path,
103 	int oflag,
104 	mode_t mode);
105 
106 extern int posix_spawn_file_actions_addclose(
107 	posix_spawn_file_actions_t *file_actions,
108 	int filedes);
109 
110 extern int posix_spawn_file_actions_adddup2(
111 	posix_spawn_file_actions_t *file_actions,
112 	int filedes,
113 	int newfiledes);
114 
115 extern int posix_spawn_file_actions_addfchdir(
116 	posix_spawn_file_actions_t *_RESTRICT_KYWD file_actions,
117 	int fd);
118 
119 extern int posix_spawnattr_init(
120 	posix_spawnattr_t *attr);
121 
122 extern int posix_spawnattr_destroy(
123 	posix_spawnattr_t *attr);
124 
125 extern int posix_spawnattr_setflags(
126 	posix_spawnattr_t *attr,
127 	short flags);
128 
129 extern int posix_spawnattr_getflags(
130 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
131 	short *_RESTRICT_KYWD flags);
132 
133 extern int posix_spawnattr_setpgroup(
134 	posix_spawnattr_t *attr,
135 	pid_t pgroup);
136 
137 extern int posix_spawnattr_getpgroup(
138 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
139 	pid_t *_RESTRICT_KYWD pgroup);
140 
141 extern int posix_spawnattr_setschedparam(
142 	posix_spawnattr_t *_RESTRICT_KYWD attr,
143 	const struct sched_param *_RESTRICT_KYWD schedparam);
144 
145 extern int posix_spawnattr_getschedparam(
146 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
147 	struct sched_param *_RESTRICT_KYWD schedparam);
148 
149 extern int posix_spawnattr_setschedpolicy(
150 	posix_spawnattr_t *attr,
151 	int schedpolicy);
152 
153 extern int posix_spawnattr_getschedpolicy(
154 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
155 	int *_RESTRICT_KYWD schedpolicy);
156 
157 extern int posix_spawnattr_setsigdefault(
158 	posix_spawnattr_t *_RESTRICT_KYWD attr,
159 	const sigset_t *_RESTRICT_KYWD sigdefault);
160 
161 extern int posix_spawnattr_getsigdefault(
162 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
163 	sigset_t *_RESTRICT_KYWD sigdefault);
164 
165 /*
166  * non-portable extensions
167  */
168 #if !defined(_STRICT_POSIX)
169 
170 extern int posix_spawn_pipe_np(
171 	pid_t *_RESTRICT_KYWD pidp,
172 	int *_RESTRICT_KYWD fdp,
173 	const char *_RESTRICT_KYWD cmd,
174 	boolean_t write,
175 	posix_spawn_file_actions_t *_RESTRICT_KYWD fact,
176 	posix_spawnattr_t *_RESTRICT_KYWD attr);
177 
178 extern int posix_spawn_file_actions_addclosefrom_np(
179 	posix_spawn_file_actions_t *file_actions,
180 	int lowfiledes);
181 
182 extern int posix_spawnattr_setsigignore_np(
183 	posix_spawnattr_t *_RESTRICT_KYWD attr,
184 	const sigset_t *_RESTRICT_KYWD sigignore);
185 
186 extern int posix_spawnattr_getsigignore_np(
187 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
188 	sigset_t *_RESTRICT_KYWD sigignore);
189 
190 /*
191  * These _np variants are not documented in the manual, but are provided for
192  * compatibility purposes with folks who have implemented this prior to
193  * standardization in POSIX 2024.
194  */
195 extern int posix_spawn_file_actions_addchdir_np(
196 	posix_spawn_file_actions_t *_RESTRICT_KYWD file_actions,
197 	const char *_RESTRICT_KYWD path);
198 
199 extern int posix_spawn_file_actions_addfchdir_np(
200 	posix_spawn_file_actions_t *_RESTRICT_KYWD file_actions,
201 	int fd);
202 
203 #endif	/* !_STRICT_POSIX */
204 
205 extern int posix_spawnattr_setsigmask(
206 	posix_spawnattr_t *_RESTRICT_KYWD attr,
207 	const sigset_t *_RESTRICT_KYWD sigmask);
208 
209 extern int posix_spawnattr_getsigmask(
210 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
211 	sigset_t *_RESTRICT_KYWD sigmask);
212 
213 #ifdef	__cplusplus
214 }
215 #endif
216 
217 #endif	/* _SPAWN_H */
218