From: Florian Forster Date: Wed, 9 Apr 2008 16:32:14 +0000 (+0200) Subject: exec plugin: Close all file descriptors but the one connected to the pipe. X-Git-Tag: collectd-4.2.7~7^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7af919ac4b76af981002875ff7bef99874f745b7;p=collectd.git exec plugin: Close all file descriptors but the one connected to the pipe. --- 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)