7 #include "pthread_impl.h"
11 extern char **environ;
16 weak_alias(dummy_0, __acquire_ptc);
17 weak_alias(dummy_0, __release_ptc);
21 int __posix_spawnx(pid_t *restrict res, const char *restrict path,
22 int (*exec)(const char *, char *const *, char *const *),
23 const posix_spawn_file_actions_t *fa,
24 const posix_spawnattr_t *restrict attr,
25 char *const argv[restrict], char *const envp[restrict])
30 posix_spawnattr_t dummy_attr = { 0 };
32 if (!attr) attr = &dummy_attr;
34 sigprocmask(SIG_BLOCK, SIGALL_SET, &oldmask);
41 sigprocmask(SIG_SETMASK, &oldmask, 0);
42 if (pid < 0) return -pid;
47 for (i=1; i<=8*__SYSCALL_SSLEN; i++) {
49 __libc_sigaction(i, 0, &sa);
50 if (sa.sa_handler!=SIG_DFL && (sa.sa_handler!=SIG_IGN ||
51 ((attr->__flags & POSIX_SPAWN_SETSIGDEF)
52 && sigismember(&attr->__def, i) ))) {
53 sa.sa_handler = SIG_DFL;
54 __libc_sigaction(i, &sa, 0);
58 if ((attr->__flags&POSIX_SPAWN_SETPGROUP) && setpgid(0, attr->__pgrp))
61 /* Use syscalls directly because pthread state is not consistent
62 * for making calls to the library wrappers... */
63 if ((attr->__flags&POSIX_SPAWN_RESETIDS) && (
64 __syscall(SYS_setgid, __syscall(SYS_getgid)) ||
65 __syscall(SYS_setuid, __syscall(SYS_getuid)) ))
68 if (fa && fa->__actions) {
71 for (op = fa->__actions; op->next; op = op->next);
72 for (; op; op = op->prev) {
75 ret = __syscall(SYS_close, op->fd);
78 ret = __syscall(SYS_dup2, op->fd, op->newfd)<0;
81 fd = __syscall(SYS_open, op->path,
82 op->oflag | O_LARGEFILE, op->mode);
86 ret = __syscall(SYS_dup2, fd, op->fd)<0;
87 __syscall(SYS_close, fd);
95 sigprocmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK)
96 ? &attr->__mask : &oldmask, 0);
98 exec(path, argv, envp ? envp : environ);
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, execve, fa, attr, argv, envp);