xref: /freebsd/include/spawn.h (revision 822042fdfca79faada89e67110b01dd9ecc05996)
1947aa542SDavid Xu /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3e58eb3c4SPedro F. Giffuni  *
4d1b2bd21SEd Schouten  * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
5947aa542SDavid Xu  * All rights reserved.
6947aa542SDavid Xu  *
7947aa542SDavid Xu  * Redistribution and use in source and binary forms, with or without
8947aa542SDavid Xu  * modification, are permitted provided that the following conditions
9947aa542SDavid Xu  * are met:
10947aa542SDavid Xu  * 1. Redistributions of source code must retain the above copyright
11947aa542SDavid Xu  *    notice, this list of conditions and the following disclaimer.
12947aa542SDavid Xu  * 2. Redistributions in binary form must reproduce the above copyright
13947aa542SDavid Xu  *    notice, this list of conditions and the following disclaimer in the
14947aa542SDavid Xu  *    documentation and/or other materials provided with the distribution.
15947aa542SDavid Xu  *
16947aa542SDavid Xu  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17947aa542SDavid Xu  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18947aa542SDavid Xu  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19947aa542SDavid Xu  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20947aa542SDavid Xu  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21947aa542SDavid Xu  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22947aa542SDavid Xu  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23947aa542SDavid Xu  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24947aa542SDavid Xu  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25947aa542SDavid Xu  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26947aa542SDavid Xu  * SUCH DAMAGE.
27947aa542SDavid Xu  */
28947aa542SDavid Xu 
29947aa542SDavid Xu #ifndef _SPAWN_H_
30947aa542SDavid Xu #define _SPAWN_H_
31947aa542SDavid Xu 
32947aa542SDavid Xu #include <sys/cdefs.h>
33947aa542SDavid Xu #include <sys/_types.h>
34947aa542SDavid Xu #include <sys/_sigset.h>
35947aa542SDavid Xu 
36947aa542SDavid Xu #ifndef _MODE_T_DECLARED
37947aa542SDavid Xu typedef	__mode_t	mode_t;
38947aa542SDavid Xu #define	_MODE_T_DECLARED
39947aa542SDavid Xu #endif
40947aa542SDavid Xu 
41947aa542SDavid Xu #ifndef _PID_T_DECLARED
42947aa542SDavid Xu typedef	__pid_t		pid_t;
43947aa542SDavid Xu #define	_PID_T_DECLARED
44947aa542SDavid Xu #endif
45947aa542SDavid Xu 
46947aa542SDavid Xu #ifndef _SIGSET_T_DECLARED
47947aa542SDavid Xu #define	_SIGSET_T_DECLARED
48947aa542SDavid Xu typedef	__sigset_t	sigset_t;
49947aa542SDavid Xu #endif
50947aa542SDavid Xu 
51947aa542SDavid Xu struct sched_param;
52947aa542SDavid Xu 
53947aa542SDavid Xu typedef struct __posix_spawnattr		*posix_spawnattr_t;
54947aa542SDavid Xu typedef struct __posix_spawn_file_actions	*posix_spawn_file_actions_t;
55947aa542SDavid Xu 
56947aa542SDavid Xu #define POSIX_SPAWN_RESETIDS		0x01
57947aa542SDavid Xu #define POSIX_SPAWN_SETPGROUP		0x02
58947aa542SDavid Xu #define POSIX_SPAWN_SETSCHEDPARAM	0x04
59947aa542SDavid Xu #define POSIX_SPAWN_SETSCHEDULER	0x08
60947aa542SDavid Xu #define POSIX_SPAWN_SETSIGDEF		0x10
61947aa542SDavid Xu #define POSIX_SPAWN_SETSIGMASK		0x20
62*822042fdSKonstantin Belousov #define	POSIX_SPAWN_DISABLE_ASLR_NP	0x40
63947aa542SDavid Xu 
64947aa542SDavid Xu __BEGIN_DECLS
65947aa542SDavid Xu /*
66947aa542SDavid Xu  * Spawn routines
676b0a300cSEd Schouten  *
686b0a300cSEd Schouten  * XXX both arrays should be __restrict, but this does not work when GCC
696b0a300cSEd Schouten  * is invoked with -std=c99.
70947aa542SDavid Xu  */
71947aa542SDavid Xu int posix_spawn(pid_t * __restrict, const char * __restrict,
72947aa542SDavid Xu     const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict,
736b0a300cSEd Schouten     char * const [], char * const []);
74947aa542SDavid Xu int posix_spawnp(pid_t * __restrict, const char * __restrict,
75947aa542SDavid Xu     const posix_spawn_file_actions_t *, const posix_spawnattr_t * __restrict,
766b0a300cSEd Schouten     char * const [], char * const []);
77947aa542SDavid Xu 
78947aa542SDavid Xu /*
79947aa542SDavid Xu  * File descriptor actions
80947aa542SDavid Xu  */
81947aa542SDavid Xu int posix_spawn_file_actions_init(posix_spawn_file_actions_t *);
82947aa542SDavid Xu int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *);
83947aa542SDavid Xu 
84947aa542SDavid Xu int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t * __restrict,
85947aa542SDavid Xu     int, const char * __restrict, int, mode_t);
86947aa542SDavid Xu int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int);
87947aa542SDavid Xu int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int);
88947aa542SDavid Xu 
8925cda42aSKonstantin Belousov #if __BSD_VISIBLE
9025cda42aSKonstantin Belousov int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *
9125cda42aSKonstantin Belousov     __restrict, const char * __restrict);
9225cda42aSKonstantin Belousov int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *,
9325cda42aSKonstantin Belousov     int);
94a18ddf77SKonstantin Belousov int posix_spawn_file_actions_addclosefrom_np(posix_spawn_file_actions_t *,
95a18ddf77SKonstantin Belousov     int);
9625cda42aSKonstantin Belousov #endif
9725cda42aSKonstantin Belousov 
98947aa542SDavid Xu /*
99947aa542SDavid Xu  * Spawn attributes
100947aa542SDavid Xu  */
101947aa542SDavid Xu int posix_spawnattr_init(posix_spawnattr_t *);
102947aa542SDavid Xu int posix_spawnattr_destroy(posix_spawnattr_t *);
103947aa542SDavid Xu 
104947aa542SDavid Xu int posix_spawnattr_getflags(const posix_spawnattr_t * __restrict,
105947aa542SDavid Xu     short * __restrict);
106947aa542SDavid Xu int posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict,
107947aa542SDavid Xu     pid_t * __restrict);
108947aa542SDavid Xu int posix_spawnattr_getschedparam(const posix_spawnattr_t * __restrict,
109947aa542SDavid Xu     struct sched_param * __restrict);
110947aa542SDavid Xu int posix_spawnattr_getschedpolicy(const posix_spawnattr_t * __restrict,
111947aa542SDavid Xu     int * __restrict);
112947aa542SDavid Xu int posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict,
113947aa542SDavid Xu     sigset_t * __restrict);
114947aa542SDavid Xu int posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict,
115947aa542SDavid Xu     sigset_t * __restrict sigmask);
116947aa542SDavid Xu 
117947aa542SDavid Xu int posix_spawnattr_setflags(posix_spawnattr_t *, short);
118947aa542SDavid Xu int posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t);
119947aa542SDavid Xu int posix_spawnattr_setschedparam(posix_spawnattr_t * __restrict,
120947aa542SDavid Xu     const struct sched_param * __restrict);
121947aa542SDavid Xu int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int);
122947aa542SDavid Xu int posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict,
123947aa542SDavid Xu     const sigset_t * __restrict);
124947aa542SDavid Xu int posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict,
125947aa542SDavid Xu     const sigset_t * __restrict);
126947aa542SDavid Xu __END_DECLS
127947aa542SDavid Xu 
128947aa542SDavid Xu #endif /* !_SPAWN_H_ */
129