xref: /illumos-gate/usr/src/test/libc-tests/tests/posix_spawn/posix_spawn_common.h (revision 93d6c51de00648a982a50fbecc433b5482953fc7)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2026 Oxide Computer Company
14  */
15 
16 #ifndef _POSIX_SPAWN_COMMON_H
17 #define	_POSIX_SPAWN_COMMON_H
18 
19 /*
20  * Common types shared between posix_spawn test programs and the spawn_child
21  * helper. The helper is exec()d via posix_spawn and reports its process state
22  * back to the parent through a pipe using these fixed-size structures.
23  *
24  * The helper's argv[1] selects the mode:
25  *
26  *   fds <fd0> <fd1> ...     Report file descriptor state
27  *   ids                     Report uid/euid/gid/egid
28  *   sched                   Report scheduling policy and priority
29  *   sidpgid                 Report session ID and process group ID
30  *   sigmask                 Report the current signal mask
31  *   sigs <sig0> <sig1> ...  Report signal dispositions
32  */
33 
34 #include <sys/types.h>
35 #include <stdbool.h>
36 #include <signal.h>
37 #include <spawn.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * Both 32-bit and 64-bit child helpers are built. Each test program exercises
45  * both to verify posix_spawn works across data models.
46  */
47 #define	POSIX_SPAWN_CHILD_HELPERS	"posix_spawn_child.32", \
48 					"posix_spawn_child.64"
49 
50 extern void posix_spawn_find_helper(char *, size_t, const char *);
51 extern void posix_spawn_pipe_setup(posix_spawn_file_actions_t *, int [2]);
52 extern bool posix_spawn_run_child(const char *, const char *,
53     posix_spawn_file_actions_t *, posix_spawnattr_t *, char *const []);
54 
55 /*
56  * Result of checking a single file descriptor. Written by spawn_child in
57  * "fds" mode, one per requested fd.
58  */
59 typedef struct spawn_fd_result {
60 	int32_t		srf_fd;		/* fd number requested */
61 	int32_t		srf_open;	/* 1 if open, 0 if not */
62 	int32_t		srf_flags;	/* O_ACCMODE from F_GETFL, or -1 */
63 	int32_t		srf_err;	/* errno if not open, 0 otherwise */
64 } spawn_fd_result_t;
65 
66 /*
67  * Result of checking a single signal's disposition. Written by spawn_child
68  * in "sigs" mode, one per requested signal.
69  */
70 typedef struct spawn_sig_result {
71 	int32_t		ssr_sig;	/* signal number */
72 	int32_t		ssr_disp;	/* 0=SIG_DFL, 1=SIG_IGN, 2=other */
73 } spawn_sig_result_t;
74 
75 /*
76  * Result of querying process IDs. Written by spawn_child in "ids" mode.
77  */
78 typedef struct spawn_id_result {
79 	uid_t		sir_uid;
80 	uid_t		sir_euid;
81 	gid_t		sir_gid;
82 	gid_t		sir_egid;
83 } spawn_id_result_t;
84 
85 /*
86  * Result of querying scheduling parameters. Written by spawn_child in
87  * "sched" mode.
88  */
89 typedef struct spawn_sched_result {
90 	int32_t		ssr_policy;
91 	int32_t		ssr_priority;
92 } spawn_sched_result_t;
93 
94 /*
95  * Result of querying session and process group IDs. Written by spawn_child
96  * in "sidpgid" mode.
97  */
98 typedef struct spawn_sidpgid_result {
99 	pid_t		sspr_sid;	/* session ID */
100 	pid_t		sspr_pgid;	/* process group ID */
101 } spawn_sidpgid_result_t;
102 
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif /* _POSIX_SPAWN_COMMON_H */
108