Re: [PATCH v2] fix start_command() bug when stdin is closed
- From
Johannes Sixt <j.sixt@viscovery.net>
- Date
- Aug 25, 2008, 13:12 UTC
- Message-ID
- <48B2AFC2.20901@viscovery.net>
- In-Reply-To
- <E1KXawS-0001gg-Ty@fencepost.gnu.org>
Paolo Bonzini schrieb:
> There is a problem in the use of dup2+close in start_command() > when one or more of file descriptors 0/1/2 are closed.
"Karl Chen pointed out a problem..." (just to give due credit).
Show 18 quoted lines
> int start_command(struct child_process *cmd)
> {
> int need_in, need_out, need_err;
> int fdin[2], fdout[2], fderr[2];
>
> /*
> + * Make sure that all file descriptors <= 2 are open, otherwise we
> + * mess them up when dup'ing pipes onto stdin/stdout/stderr. Since
> + * we are at it, open a file descriptor on /dev/null to use it later.
> + */
> + if (devnull_fd == -1)
> + {
> + devnull_fd = open("/dev/null", O_RDWR);
> + while (devnull_fd >= 0 && devnull_fd <= 2)
> + devnull_fd = dup(devnull_fd);
> + if (devnull_fd == -1)
> + die("opening /dev/null failed (%s)", strerror(errno));
> + }Except for the insane GNU style indentation ;-) this makes a lot of sense.
Acked-by: Johannes Sixt <johannes.sixt@telecom.at>
The changes to the MINGW32 section are good (they pass the test suite). Thanks for taking care of that.
-- Hannes