diff options
author | Johannes Sixt <j6t@kdbg.org> | 2010-01-15 21:12:18 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-01-16 16:43:53 -0800 |
commit | 75301f90159a505f3683a5eba10174928dc30fb1 (patch) | |
tree | 996c0fdd16348c4496b3a35fee1d249036d58a91 /t/t5515/refs.br-remote-explicit_remote-explicit | |
parent | Windows: simplify the pipe(2) implementation (diff) | |
download | tgif-75301f90159a505f3683a5eba10174928dc30fb1.tar.xz |
Windows: avoid the "dup dance" when spawning a child process
When stdin, stdout, or stderr must be redirected for a child process that
on Windows is spawned using one of the spawn() functions of Microsoft's
C runtime, then there is no choice other than to
1. make a backup copy of fd 0,1,2 with dup
2. dup2 the redirection source fd into 0,1,2
3. spawn
4. dup2 the backup back into 0,1,2
5. close the backup copy and the redirection source
We used this idiom as well -- but we are not using the spawn() functions
anymore!
Instead, we have our own implementation. We had hardcoded that stdin,
stdout, and stderr of the child process were inherited from the parent's
fds 0, 1, and 2. But we can actually specify any fd.
With this patch, the fds to inherit are passed from start_command()'s
WIN32 section to our spawn implementation. This way, we can avoid the
backup copies of the fds.
The backup copies were a bug waiting to surface: The OS handles underlying
the dup()ed fds were inherited by the child process (but were not
associated with a file descriptor in the child). Consequently, the file or
pipe represented by the OS handle remained open even after the backup copy
was closed in the parent process until the child exited.
Since our implementation of pipe() creates non-inheritable OS handles, we
still dup() file descriptors in start_command() because dup() happens to
create inheritable duplicates. (A nice side effect is that the fd cleanup
in start_command is the same for Windows and Unix and remains unchanged.)
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t5515/refs.br-remote-explicit_remote-explicit')
0 files changed, 0 insertions, 0 deletions