5 #include "stdio_impl.h"
6 #include "pthread_impl.h"
12 weak_alias(dummy_0, __acquire_ptc);
13 weak_alias(dummy_0, __release_ptc);
17 FILE *popen(const char *cmd, const char *mode)
23 const char *modes = "rw", *mi = strchr(modes, *mode);
32 if (pipe2(p, O_CLOEXEC)) return NULL;
33 f = fdopen(p[op], mode);
35 __syscall(SYS_close, p[0]);
36 __syscall(SYS_close, p[1]);
40 sigprocmask(SIG_BLOCK, SIGALL_SET, &old);
47 __syscall(SYS_close, p[1-op]);
48 sigprocmask(SIG_SETMASK, &old, 0);
57 /* See notes in system.c for why this is needed. */
58 for (i=1; i<=8*__SYSCALL_SSLEN; i++) {
60 __libc_sigaction(i, 0, &sa);
61 if (sa.sa_handler!=SIG_IGN && sa.sa_handler!=SIG_DFL) {
62 sa.sa_handler = SIG_DFL;
63 __libc_sigaction(i, &sa, 0);
66 if (dup2(p[1-op], 1-op) < 0) _exit(127);
67 fcntl(1-op, F_SETFD, 0);
68 if (p[0] != 1-op) __syscall(SYS_close, p[0]);
69 if (p[1] != 1-op) __syscall(SYS_close, p[1]);
70 sigprocmask(SIG_SETMASK, &old, 0);
71 execl("/bin/sh", "sh", "-c", cmd, (char *)0);