From 23a2f7ca3b960cb563e5003fae88eda7278a0021 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 11 Mar 2014 20:07:16 -0700 Subject: * stream.c (open_process): Close the original pipe file descriptor in the child process after dup2-ing it to standard input or standard output, so the child doesn't have to references to the pipe. --- ChangeLog | 6 ++++++ stream.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 55fec2ff..b392409d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-03-11 Kaz Kylheku + + * stream.c (open_process): Close the original pipe file descriptor + in the child process after dup2-ing it to standard input or standard + output, so the child doesn't have to references to the pipe. + 2014-03-10 Kaz Kylheku * stream.c (pipe_close): Restructured the function a bit. diff --git a/stream.c b/stream.c index 7d073fc1..dbe3e9ff 100644 --- a/stream.c +++ b/stream.c @@ -2158,9 +2158,13 @@ val open_process(val name, val mode_str, val args) if (pid == 0) { if (input) { dup2(fd[1], STDOUT_FILENO); + if (fd[1] != STDOUT_FILENO) /* You never know */ + close(fd[1]); close(fd[0]); } else { dup2(fd[0], STDIN_FILENO); + if (fd[0] != STDIN_FILENO) /* You never know */ + close(fd[0]); close(fd[1]); } -- cgit v1.2.3