xref: /xnu-10002.1.13/tests/subsystem_root_path.h (revision 1031c584a5e37aff177559b9f69dbd3c8c3fd30a)
1*1031c584SApple OSS Distributions #include <unistd.h>
2*1031c584SApple OSS Distributions #include <spawn.h>
3*1031c584SApple OSS Distributions #include <sys/wait.h>
4*1031c584SApple OSS Distributions 
5*1031c584SApple OSS Distributions #define SUBSYSTEM_ROOT_PATH_KEY "subsystem_root_path"
6*1031c584SApple OSS Distributions 
7*1031c584SApple OSS Distributions #define HELPER_BEHAVIOR_NOT_SET    "not_set"
8*1031c584SApple OSS Distributions #define HELPER_BEHAVIOR_SET        "set"
9*1031c584SApple OSS Distributions #define HELPER_BEHAVIOR_FORK_EXEC  "fork_exec"
10*1031c584SApple OSS Distributions #define HELPER_BEHAVIOR_SPAWN      "spawn"
11*1031c584SApple OSS Distributions 
12*1031c584SApple OSS Distributions static int
_spawn_and_wait(char ** args,posix_spawnattr_t * attr)13*1031c584SApple OSS Distributions _spawn_and_wait(char ** args, posix_spawnattr_t *attr)
14*1031c584SApple OSS Distributions {
15*1031c584SApple OSS Distributions 	int pid;
16*1031c584SApple OSS Distributions 	int status;
17*1031c584SApple OSS Distributions 
18*1031c584SApple OSS Distributions 	if (posix_spawn(&pid, args[0], NULL, attr, args, NULL)) {
19*1031c584SApple OSS Distributions 		return -1;
20*1031c584SApple OSS Distributions 	}
21*1031c584SApple OSS Distributions 	if (waitpid(pid, &status, 0) < 0) {
22*1031c584SApple OSS Distributions 		return -1;
23*1031c584SApple OSS Distributions 	}
24*1031c584SApple OSS Distributions 
25*1031c584SApple OSS Distributions 	if (WIFEXITED(status) && (WEXITSTATUS(status) == 0)) {
26*1031c584SApple OSS Distributions 		return 0;
27*1031c584SApple OSS Distributions 	}
28*1031c584SApple OSS Distributions 
29*1031c584SApple OSS Distributions 	return -1;
30*1031c584SApple OSS Distributions }
31