about summary refs log tree commit diff
path: root/src/stdio/popen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdio/popen.c')
-rw-r--r--src/stdio/popen.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/stdio/popen.c b/src/stdio/popen.c
index 1d33e9d6..50765daa 100644
--- a/src/stdio/popen.c
+++ b/src/stdio/popen.c
@@ -31,9 +31,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);
 	}