lists.zerezo.com
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2] fix start_command() bug when stdin is closed
- Date: Mon, 25 Aug 2008 15:12:34 +0200
- From: Johannes Sixt <j.sixt@xxxxxxxxxxxxx>
- Subject: Re: [PATCH v2] fix start_command() bug when stdin is closed
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).
> 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@xxxxxxxxxx>
The changes to the MINGW32 section are good (they pass the test suite).
Thanks for taking care of that.
-- Hannes
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html