author | Florian Forster <octo@crystal.wlan.home.verplant.org> | |
Wed, 9 Apr 2008 16:45:38 +0000 (18:45 +0200) | ||
committer | Florian Forster <octo@crystal.wlan.home.verplant.org> | |
Wed, 9 Apr 2008 16:45:38 +0000 (18:45 +0200) |
Conflicts:
src/exec.c
src/exec.c
1 | 2 | |||
---|---|---|---|---|
src/exec.c | patch | | diff1 | | diff2 | | blob | history |
diff --cc src/exec.c
index 70c1c18476c1683d7d555b25c16282173402806f,5eae906bee3f12ca74faeb07382488de7f36c6f6..07c35c9bcf36d0e307ebbc48a93fb1e7fafa57e1
--- 1/src/exec.c
--- 2/src/exec.c
+++ b/src/exec.c
}
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]))
++ if ((fd == fd_pipe_in[0])
++ || (fd == fd_pipe_out[1])
++ || (fd == fd_pipe_err[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
- * `out' pipe first. */
- if (fd_pipe_out[1] == STDIN_FILENO)
- {
- int new_fileno = (fd_pipe_in[0] == STDOUT_FILENO)
- ? STDERR_FILENO : STDOUT_FILENO;
- dup2 (fd_pipe_out[1], new_fileno);
- close (fd_pipe_out[1]);
- fd_pipe_out[1] = new_fileno;
- }
- /* Now `fd_pipe_out[1]' is either `STDOUT' or `STDERR', but definitely not
- * `STDIN_FILENO'. */
-
/* Connect the `in' pipe to STDIN */
if (fd_pipe_in[0] != STDIN_FILENO)
{