xref: /freebsd/include/spawn.h (revision ade8a27ea4c28d12fabc2d5f8e44386a3add23d1)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _SPAWN_H_
30 #define _SPAWN_H_
31 
32 #include <sys/cdefs.h>
33 #include <sys/_types.h>
34 #include <sys/_sigset.h>
35 
36 #ifndef _MODE_T_DECLARED
37 typedef	__mode_t	mode_t;
38 #define	_MODE_T_DECLARED
39 #endif
40 
41 #ifndef _PID_T_DECLARED
42 typedef	__pid_t		pid_t;
43 #define	_PID_T_DECLARED
44 #endif
45 
46 #ifndef _SIGSET_T_DECLARED
47 #define	_SIGSET_T_DECLARED
48 typedef	__sigset_t	sigset_t;
49 #endif
50 
51 struct sched_param;
52 
53 typedef struct __posix_spawnattr		*posix_spawnattr_t;
54 typedef struct __posix_spawn_file_actions	*posix_spawn_file_actions_t;
55 
56 #define POSIX_SPAWN_RESETIDS		0x01
57 #define POSIX_SPAWN_SETPGROUP		0x02
58 #define POSIX_SPAWN_SETSCHEDPARAM	0x04
59 #define POSIX_SPAWN_SETSCHEDULER	0x08
60 #define POSIX_SPAWN_SETSIGDEF		0x10
61 #define POSIX_SPAWN_SETSIGMASK		0x20
62 #define	POSIX_SPAWN_DISABLE_ASLR_NP	0x40
63 
64 __BEGIN_DECLS
65 /*
66  * Spawn routines
67  *
68  * XXX both arrays should be __restrict, but this does not work when GCC
69  * is invoked with -std=c99.
70  */
71 int posix_spawn(pid_t * __restrict, const char * __restrict,
72     const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict,
73     char * const [], char * const []);
74 int posix_spawnp(pid_t * __restrict, const char * __restrict,
75     const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict,
76     char * const [], char * const []);
77 
78 /*
79  * File descriptor actions
80  */
81 int posix_spawn_file_actions_init(posix_spawn_file_actions_t *);
82 int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *);
83 
84 int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t * __restrict,
85     int, const char * __restrict, int, mode_t);
86 int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int);
87 int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int);
88 int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t *
89     __restrict, const char * __restrict);
90 int posix_spawn_file_actions_addfchdir(posix_spawn_file_actions_t *,
91     int);
92 
93 #if __BSD_VISIBLE
94 int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *
95     __restrict, const char * __restrict);
96 int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *,
97     int);
98 int posix_spawn_file_actions_addclosefrom_np(posix_spawn_file_actions_t *,
99     int);
100 #endif
101 
102 /*
103  * Spawn attributes
104  */
105 int posix_spawnattr_init(posix_spawnattr_t *);
106 int posix_spawnattr_destroy(posix_spawnattr_t *);
107 
108 int posix_spawnattr_getflags(const posix_spawnattr_t * __restrict,
109     short * __restrict);
110 int posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict,
111     pid_t * __restrict);
112 int posix_spawnattr_getschedparam(const posix_spawnattr_t * __restrict,
113     struct sched_param * __restrict);
114 int posix_spawnattr_getschedpolicy(const posix_spawnattr_t * __restrict,
115     int * __restrict);
116 int posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict,
117     sigset_t * __restrict);
118 int posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict,
119     sigset_t * __restrict sigmask);
120 
121 int posix_spawnattr_setflags(posix_spawnattr_t *, short);
122 int posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t);
123 int posix_spawnattr_setschedparam(posix_spawnattr_t * __restrict,
124     const struct sched_param * __restrict);
125 int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int);
126 int posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict,
127     const sigset_t * __restrict);
128 int posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict,
129     const sigset_t * __restrict);
130 
131 #if __BSD_VISIBLE
132 int posix_spawnattr_setexecfd_np(posix_spawnattr_t * __restrict, int);
133 int posix_spawnattr_setprocdescp_np(const posix_spawnattr_t * __restrict,
134     int * __restrict, int);
135 int posix_spawnattr_getexecfd_np(const posix_spawnattr_t * __restrict,
136     int * __restrict);
137 int posix_spawnattr_getprocdescp_np(const posix_spawnattr_t * __restrict,
138     int ** __restrict, int * __restrict);
139 #endif
140 
141 __END_DECLS
142 
143 #endif /* !_SPAWN_H_ */
144