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)) ))
57 for (op = fa->__actions; op; op = op->next) {
60 ret = __syscall(SYS_close, op->fd);
63 ret = __syscall(SYS_dup2, op->fd, op->newfd)<0;
66 fd = __syscall(SYS_open, op->path,
67 op->oflag | O_LARGEFILE, op->mode);
71 ret = __syscall(SYS_dup2, fd, op->fd)<0;
72 __syscall(SYS_close, fd);
80 sigprocmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK)
81 ? &attr->__mask : &oldmask, 0);
83 if (envp) environ = envp;
90 int posix_spawn(pid_t *res, const char *path,
91 const posix_spawn_file_actions_t *fa,
92 const posix_spawnattr_t *attr, char **argv, char **envp)
94 return __posix_spawnx(res, path, execv, fa, attr, argv, envp);