/*
* 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'.
*/
}
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)
pbuffer = buffer + len;
}
else
- pbuffer = buffer;
- }
+ pbuffer = buffer;
+ }
else if (FD_ISSET(fd_err, ©))
{
char *pnl;