13 int __posix_spawnx(pid_t *restrict res, const char *restrict path,
14 int (*exec)(const char *, char *const *),
15 const posix_spawn_file_actions_t *fa,
16 const posix_spawnattr_t *restrict attr,
17 char *const argv[restrict], char *const envp[restrict])
22 posix_spawnattr_t dummy_attr = { 0 };
24 if (!attr) attr = &dummy_attr;
26 sigprocmask(SIG_BLOCK, (void *)(uint64_t []){-1}, &oldmask);
30 sigprocmask(SIG_SETMASK, &oldmask, 0);
31 if (pid < 0) return -pid;
36 for (i=1; i<=64; i++) {
39 if (sa.sa_handler!=SIG_IGN ||
40 ((attr->__flags & POSIX_SPAWN_SETSIGDEF)
41 && sigismember(&attr->__def, i) )) {
42 sa.sa_handler = SIG_DFL;
47 if ((attr->__flags&POSIX_SPAWN_SETPGROUP) && setpgid(0, attr->__pgrp))
50 /* Use syscalls directly because pthread state is not consistent
51 * for making calls to the library wrappers... */
52 if ((attr->__flags&POSIX_SPAWN_RESETIDS) && (
53 __syscall(SYS_setgid, __syscall(SYS_getgid)) ||
54 __syscall(SYS_setuid, __syscall(SYS_getuid)) ))
57 if (fa && fa->__actions) {
60 for (op = fa->__actions; op->next; op = op->next);
61 for (; op; op = op->prev) {
64 ret = __syscall(SYS_close, op->fd);
67 ret = __syscall(SYS_dup2, op->fd, op->newfd)<0;
70 fd = __syscall(SYS_open, op->path,
71 op->oflag | O_LARGEFILE, op->mode);
75 ret = __syscall(SYS_dup2, fd, op->fd)<0;
76 __syscall(SYS_close, fd);
84 sigprocmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK)
85 ? &attr->__mask : &oldmask, 0);
87 if (envp) environ = (char **)envp;
94 int posix_spawn(pid_t *restrict res, const char *restrict path,
95 const posix_spawn_file_actions_t *fa,
96 const posix_spawnattr_t *restrict attr,
97 char *const argv[restrict], char *const envp[restrict])
99 return __posix_spawnx(res, path, execv, fa, attr, argv, envp);