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, char **argv, char **envp)
19 posix_spawnattr_t dummy_attr = { 0 };
21 if (!attr) attr = &dummy_attr;
23 sigprocmask(SIG_BLOCK, (void *)(uint64_t []){-1}, &oldmask);
24 pid = __syscall(SYS_fork);
27 sigprocmask(SIG_SETMASK, &oldmask, 0);
28 if (pid < 0) return -pid;
33 for (i=1; i<=64; i++) {
36 if (sa.sa_handler!=SIG_IGN ||
37 ((attr->__flags & POSIX_SPAWN_SETSIGDEF)
38 && sigismember(&attr->__def, i) )) {
39 sa.sa_handler = SIG_DFL;
44 if ((attr->__flags&POSIX_SPAWN_SETPGROUP) && setpgid(0, attr->__pgrp))
47 /* Use syscalls directly because pthread state is not consistent
48 * for making calls to the library wrappers... */
49 if ((attr->__flags&POSIX_SPAWN_RESETIDS) && (
50 __syscall(SYS_setgid, __syscall(SYS_getgid)) ||
51 __syscall(SYS_setuid, __syscall(SYS_getuid)) ))
54 if (fa && fa->__actions) {
57 for (op = fa->__actions; op->next; op = op->next);
58 for (; op; op = op->prev) {
61 ret = __syscall(SYS_close, op->fd);
64 ret = __syscall(SYS_dup2, op->fd, op->newfd)<0;
67 fd = __syscall(SYS_open, op->path,
68 op->oflag | O_LARGEFILE, op->mode);
72 ret = __syscall(SYS_dup2, fd, op->fd)<0;
73 __syscall(SYS_close, fd);
81 sigprocmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK)
82 ? &attr->__mask : &oldmask, 0);
84 if (envp) environ = envp;
91 int posix_spawn(pid_t *res, const char *path,
92 const posix_spawn_file_actions_t *fa,
93 const posix_spawnattr_t *attr, char **argv, char **envp)
95 return __posix_spawnx(res, path, execv, fa, attr, argv, envp);