10 extern char **environ;
15 weak_alias(dummy_0, __acquire_ptc);
16 weak_alias(dummy_0, __release_ptc);
20 int __posix_spawnx(pid_t *restrict res, const char *restrict path,
21 int (*exec)(const char *, char *const *),
22 const posix_spawn_file_actions_t *fa,
23 const posix_spawnattr_t *restrict attr,
24 char *const argv[restrict], char *const envp[restrict])
29 posix_spawnattr_t dummy_attr = { 0 };
31 if (!attr) attr = &dummy_attr;
33 sigprocmask(SIG_BLOCK, (void *)(uint64_t []){-1}, &oldmask);
40 sigprocmask(SIG_SETMASK, &oldmask, 0);
41 if (pid < 0) return -pid;
46 for (i=1; i<=64; i++) {
49 if (sa.sa_handler!=SIG_IGN ||
50 ((attr->__flags & POSIX_SPAWN_SETSIGDEF)
51 && sigismember(&attr->__def, i) )) {
52 sa.sa_handler = SIG_DFL;
57 if ((attr->__flags&POSIX_SPAWN_SETPGROUP) && setpgid(0, attr->__pgrp))
60 /* Use syscalls directly because pthread state is not consistent
61 * for making calls to the library wrappers... */
62 if ((attr->__flags&POSIX_SPAWN_RESETIDS) && (
63 __syscall(SYS_setgid, __syscall(SYS_getgid)) ||
64 __syscall(SYS_setuid, __syscall(SYS_getuid)) ))
67 if (fa && fa->__actions) {
70 for (op = fa->__actions; op->next; op = op->next);
71 for (; op; op = op->prev) {
74 ret = __syscall(SYS_close, op->fd);
77 ret = __syscall(SYS_dup2, op->fd, op->newfd)<0;
80 fd = __syscall(SYS_open, op->path,
81 op->oflag | O_LARGEFILE, op->mode);
85 ret = __syscall(SYS_dup2, fd, op->fd)<0;
86 __syscall(SYS_close, fd);
94 sigprocmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK)
95 ? &attr->__mask : &oldmask, 0);
97 if (envp) environ = (char **)envp;
104 int posix_spawn(pid_t *restrict res, const char *restrict path,
105 const posix_spawn_file_actions_t *fa,
106 const posix_spawnattr_t *restrict attr,
107 char *const argv[restrict], char *const envp[restrict])
109 return __posix_spawnx(res, path, execv, fa, attr, argv, envp);