11 int __posix_spawnx(pid_t *res, const char *path,
12 int (*exec)(const char *, char *const *),
13 const posix_spawn_file_actions_t *fa,
14 const posix_spawnattr_t *attr,
15 char *const argv[], char *const envp[])
20 posix_spawnattr_t dummy_attr = { 0 };
22 if (!attr) attr = &dummy_attr;
24 sigprocmask(SIG_BLOCK, (void *)(uint64_t []){-1}, &oldmask);
25 pid = __syscall(SYS_fork);
28 sigprocmask(SIG_SETMASK, &oldmask, 0);
29 if (pid < 0) return -pid;
34 for (i=1; i<=64; i++) {
37 if (sa.sa_handler!=SIG_IGN ||
38 ((attr->__flags & POSIX_SPAWN_SETSIGDEF)
39 && sigismember(&attr->__def, i) )) {
40 sa.sa_handler = SIG_DFL;
45 if ((attr->__flags&POSIX_SPAWN_SETPGROUP) && setpgid(0, attr->__pgrp))
48 /* Use syscalls directly because pthread state is not consistent
49 * for making calls to the library wrappers... */
50 if ((attr->__flags&POSIX_SPAWN_RESETIDS) && (
51 __syscall(SYS_setgid, __syscall(SYS_getgid)) ||
52 __syscall(SYS_setuid, __syscall(SYS_getuid)) ))
55 if (fa && fa->__actions) {
58 for (op = fa->__actions; op->next; op = op->next);
59 for (; op; op = op->prev) {
62 ret = __syscall(SYS_close, op->fd);
65 ret = __syscall(SYS_dup2, op->fd, op->newfd)<0;
68 fd = __syscall(SYS_open, op->path,
69 op->oflag | O_LARGEFILE, op->mode);
73 ret = __syscall(SYS_dup2, fd, op->fd)<0;
74 __syscall(SYS_close, fd);
82 sigprocmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK)
83 ? &attr->__mask : &oldmask, 0);
85 if (envp) environ = (char **)envp;
92 int posix_spawn(pid_t *res, const char *path,
93 const posix_spawn_file_actions_t *fa,
94 const posix_spawnattr_t *attr,
95 char *const argv[], char *const envp[])
97 return __posix_spawnx(res, path, execv, fa, attr, argv, envp);