From 7af919ac4b76af981002875ff7bef99874f745b7 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 9 Apr 2008 18:32:14 +0200 Subject: [PATCH] exec plugin: Close all file descriptors but the one connected to the pipe. --- src/exec.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/exec.c b/src/exec.c index 0ab259dc..52dd831d 100644 --- a/src/exec.c +++ b/src/exec.c @@ -264,7 +264,17 @@ static int fork_child (program_list_t *pl) } else if (pl->pid == 0) { - close (fd_pipe[0]); + int fd_num; + int fd; + + /* Close all file descriptors but the pipe end we need. */ + fd_num = getdtablesize (); + for (fd = 0; fd < fd_num; fd++) + { + if (fd == fd_pipe[1]) + continue; + close (fd); + } /* Connect the pipe to STDOUT and STDERR */ if (fd_pipe[1] != STDOUT_FILENO) -- 2.30.2