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