xref: /illumos-gate/usr/src/head/spawn.h (revision e2d5066a004ea2b47d7cd687f38c43d6cfb21275)
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  * Copyright 2026 Oxide Computer Company
32  */
33 
34 #ifndef _SPAWN_H
35 #define	_SPAWN_H
36 
37 #include <sys/feature_tests.h>
38 #include <sys/types.h>
39 #include <sys/spawn.h>
40 #include <signal.h>
41 #include <sched.h>
42 
43 #ifdef	__cplusplus
44 extern "C" {
45 #endif
46 
47 typedef struct {
48 	void *__spawn_attrp;	/* implementation-private */
49 } posix_spawnattr_t;
50 
51 typedef struct {
52 	void *__file_attrp;	/* implementation-private */
53 } posix_spawn_file_actions_t;
54 
55 extern int posix_spawn(
56 	pid_t *_RESTRICT_KYWD pid,
57 	const char *_RESTRICT_KYWD path,
58 	const posix_spawn_file_actions_t *file_actions,
59 	const posix_spawnattr_t *_RESTRICT_KYWD attrp,
60 	char *const *_RESTRICT_KYWD argv,
61 	char *const *_RESTRICT_KYWD envp);
62 
63 extern int posix_spawnp(
64 	pid_t *_RESTRICT_KYWD pid,
65 	const char *_RESTRICT_KYWD file,
66 	const posix_spawn_file_actions_t *file_actions,
67 	const posix_spawnattr_t *_RESTRICT_KYWD attrp,
68 	char *const *_RESTRICT_KYWD argv,
69 	char *const *_RESTRICT_KYWD envp);
70 
71 extern int posix_spawn_file_actions_init(
72 	posix_spawn_file_actions_t *file_actions);
73 
74 extern int posix_spawn_file_actions_destroy(
75 	posix_spawn_file_actions_t *file_actions);
76 
77 extern int posix_spawn_file_actions_addchdir(
78 	posix_spawn_file_actions_t *_RESTRICT_KYWD file_actions,
79 	const char *_RESTRICT_KYWD path);
80 
81 extern int posix_spawn_file_actions_addopen(
82 	posix_spawn_file_actions_t *_RESTRICT_KYWD file_actions,
83 	int filedes,
84 	const char *_RESTRICT_KYWD path,
85 	int oflag,
86 	mode_t mode);
87 
88 extern int posix_spawn_file_actions_addclose(
89 	posix_spawn_file_actions_t *file_actions,
90 	int filedes);
91 
92 extern int posix_spawn_file_actions_adddup2(
93 	posix_spawn_file_actions_t *file_actions,
94 	int filedes,
95 	int newfiledes);
96 
97 extern int posix_spawn_file_actions_addfchdir(
98 	posix_spawn_file_actions_t *_RESTRICT_KYWD file_actions,
99 	int fd);
100 
101 extern int posix_spawnattr_init(
102 	posix_spawnattr_t *attr);
103 
104 extern int posix_spawnattr_destroy(
105 	posix_spawnattr_t *attr);
106 
107 extern int posix_spawnattr_setflags(
108 	posix_spawnattr_t *attr,
109 	short flags);
110 
111 extern int posix_spawnattr_getflags(
112 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
113 	short *_RESTRICT_KYWD flags);
114 
115 extern int posix_spawnattr_setpgroup(
116 	posix_spawnattr_t *attr,
117 	pid_t pgroup);
118 
119 extern int posix_spawnattr_getpgroup(
120 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
121 	pid_t *_RESTRICT_KYWD pgroup);
122 
123 extern int posix_spawnattr_setschedparam(
124 	posix_spawnattr_t *_RESTRICT_KYWD attr,
125 	const struct sched_param *_RESTRICT_KYWD schedparam);
126 
127 extern int posix_spawnattr_getschedparam(
128 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
129 	struct sched_param *_RESTRICT_KYWD schedparam);
130 
131 extern int posix_spawnattr_setschedpolicy(
132 	posix_spawnattr_t *attr,
133 	int schedpolicy);
134 
135 extern int posix_spawnattr_getschedpolicy(
136 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
137 	int *_RESTRICT_KYWD schedpolicy);
138 
139 extern int posix_spawnattr_setsigdefault(
140 	posix_spawnattr_t *_RESTRICT_KYWD attr,
141 	const sigset_t *_RESTRICT_KYWD sigdefault);
142 
143 extern int posix_spawnattr_getsigdefault(
144 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
145 	sigset_t *_RESTRICT_KYWD sigdefault);
146 
147 /*
148  * non-portable extensions
149  */
150 #if !defined(_STRICT_POSIX)
151 
152 extern int posix_spawn_pipe_np(
153 	pid_t *_RESTRICT_KYWD pidp,
154 	int *_RESTRICT_KYWD fdp,
155 	const char *_RESTRICT_KYWD cmd,
156 	boolean_t write,
157 	posix_spawn_file_actions_t *_RESTRICT_KYWD fact,
158 	posix_spawnattr_t *_RESTRICT_KYWD attr);
159 
160 extern int posix_spawn_file_actions_addclosefrom_np(
161 	posix_spawn_file_actions_t *file_actions,
162 	int lowfiledes);
163 
164 extern int posix_spawnattr_setsigignore_np(
165 	posix_spawnattr_t *_RESTRICT_KYWD attr,
166 	const sigset_t *_RESTRICT_KYWD sigignore);
167 
168 extern int posix_spawnattr_getsigignore_np(
169 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
170 	sigset_t *_RESTRICT_KYWD sigignore);
171 
172 /*
173  * These _np variants are not documented in the manual, but are provided for
174  * compatibility purposes with folks who have implemented this prior to
175  * standardization in POSIX 2024.
176  */
177 extern int posix_spawn_file_actions_addchdir_np(
178 	posix_spawn_file_actions_t *_RESTRICT_KYWD file_actions,
179 	const char *_RESTRICT_KYWD path);
180 
181 extern int posix_spawn_file_actions_addfchdir_np(
182 	posix_spawn_file_actions_t *_RESTRICT_KYWD file_actions,
183 	int fd);
184 
185 #endif	/* !_STRICT_POSIX */
186 
187 extern int posix_spawnattr_setsigmask(
188 	posix_spawnattr_t *_RESTRICT_KYWD attr,
189 	const sigset_t *_RESTRICT_KYWD sigmask);
190 
191 extern int posix_spawnattr_getsigmask(
192 	const posix_spawnattr_t *_RESTRICT_KYWD attr,
193 	sigset_t *_RESTRICT_KYWD sigmask);
194 
195 #ifdef	__cplusplus
196 }
197 #endif
198 
199 #endif	/* _SPAWN_H */
200