X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fexec.c;h=5eae906bee3f12ca74faeb07382488de7f36c6f6;hb=48b794525072b1ff00a90497ef0bb1f4030510f4;hp=b25e76979ebb2322db79a5acdd746d28ecf73335;hpb=89783745dc59079eab34e0c52de6e5e972f50eb2;p=collectd.git diff --git a/src/exec.c b/src/exec.c index b25e7697..5eae906b 100644 --- a/src/exec.c +++ b/src/exec.c @@ -334,7 +334,7 @@ static void exec_child (program_list_t *pl) /* {{{ */ glist[0] = gid; glist_len = 1; - if (gid != egid) + if ((gid != egid) && (egid != -1)) { glist[1] = egid; glist_len = 2; @@ -421,8 +421,17 @@ static int fork_child (program_list_t *pl, int *fd_in, int *fd_out) /* {{{ */ } else if (pid == 0) { - close (fd_pipe_in[1]); - close (fd_pipe_out[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])) + continue; + close (fd); + } /* If the `out' pipe has the filedescriptor STDIN we have to be careful * with the `dup's below. So, if this is the case we have to handle the