X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fstdio%2Fpopen.c;h=4f9d6e9ec92a95b85507d2a42dc6187b1809898b;hp=1d33e9d692fae195b41af7ca8179e972c155c710;hb=9c21f4342c787e04a9e31ad8a1d87a65c89968ca;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 diff --git a/src/stdio/popen.c b/src/stdio/popen.c index 1d33e9d6..4f9d6e9e 100644 --- a/src/stdio/popen.c +++ b/src/stdio/popen.c @@ -1,4 +1,11 @@ #include "stdio_impl.h" +#include "syscall.h" + +static inline void nc_close(int fd) +{ + __syscall(SYS_close, fd); +} +#define close(x) nc_close(x) FILE *popen(const char *cmd, const char *mode) { @@ -31,9 +38,9 @@ FILE *popen(const char *cmd, const char *mode) close(p[1]); return NULL; case 0: - dup2(p[1-op], 1-op); - close(p[0]); - close(p[1]); + if (dup2(p[1-op], 1-op) < 0) _exit(127); + if (p[0] != 1-op) close(p[0]); + if (p[1] != 1-op) close(p[1]); execl("/bin/sh", "sh", "-c", cmd, (char *)0); _exit(127); }