X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fexec.c;h=07c35c9bcf36d0e307ebbc48a93fb1e7fafa57e1;hb=a019b6c8144745db63c599680bd693ac02f11666;hp=b0b716f6031d77a776f1ee11c568b6cf3349bfdc;hpb=a6ee4ce819e373d257d01a232666f7579d41b00c;p=collectd.git diff --git a/src/exec.c b/src/exec.c index b0b716f6..07c35c9b 100644 --- a/src/exec.c +++ b/src/exec.c @@ -380,7 +380,7 @@ static void exec_child (program_list_t *pl) /* {{{ */ /* * Creates three pipes (one for reading, one for writing and one for errors), - * forks a child, sets up the pipes so that fd_in is connected to STDIN of + * forks a child, sets up the pipes so that fd_in is connected to STDIN of * the child and fd_out is connected to STDOUT and fd_err is connected to STDERR * of the child. Then is calls `exec_child'. */ @@ -429,9 +429,19 @@ static int fork_child (program_list_t *pl, int *fd_in, int *fd_out, int *fd_err) } else if (pid == 0) { - close (fd_pipe_in[1]); - close (fd_pipe_out[0]); - close (fd_pipe_err[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_in[0]) + || (fd == fd_pipe_out[1]) + || (fd == fd_pipe_err[1])) + continue; + close (fd); + } /* Connect the `in' pipe to STDIN */ if (fd_pipe_in[0] != STDIN_FILENO) @@ -564,8 +574,8 @@ static void *exec_read_one (void *arg) /* {{{ */ pbuffer = buffer + len; } else - pbuffer = buffer; - } + pbuffer = buffer; + } else if (FD_ISSET(fd_err, ©)) { char *pnl;