2 #include "stdio_impl.h"
3 #include "pthread_impl.h"
9 weak_alias(dummy_0, __acquire_ptc);
10 weak_alias(dummy_0, __release_ptc);
14 FILE *popen(const char *cmd, const char *mode)
20 const char *modes = "rw", *mi = strchr(modes, *mode);
29 if (pipe2(p, O_CLOEXEC)) return NULL;
30 f = fdopen(p[op], mode);
32 __syscall(SYS_close, p[0]);
33 __syscall(SYS_close, p[1]);
37 sigprocmask(SIG_BLOCK, SIGALL_SET, &old);
44 __syscall(SYS_close, p[1-op]);
45 sigprocmask(SIG_SETMASK, &old, 0);
54 /* See notes in system.c for why this is needed. */
55 for (i=1; i<=8*__SYSCALL_SSLEN; i++) {
57 __libc_sigaction(i, 0, &sa);
58 if (sa.sa_handler!=SIG_IGN && sa.sa_handler!=SIG_DFL) {
59 sa.sa_handler = SIG_DFL;
60 __libc_sigaction(i, &sa, 0);
63 if (dup2(p[1-op], 1-op) < 0) _exit(127);
64 fcntl(1-op, F_SETFD, 0);
65 if (p[0] != 1-op) __syscall(SYS_close, p[0]);
66 if (p[1] != 1-op) __syscall(SYS_close, p[1]);
67 sigprocmask(SIG_SETMASK, &old, 0);
68 execl("/bin/sh", "sh", "-c", cmd, (char *)0);