summaryrefslogtreecommitdiff
path: root/notes.c
diff options
context:
space:
mode:
authorJohannes Sixt <j6t@kdbg.org>2010-01-15 20:12:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2010-01-17 00:43:53 (GMT)
commit75301f90159a505f3683a5eba10174928dc30fb1 (patch)
tree996c0fdd16348c4496b3a35fee1d249036d58a91 /notes.c
parent3e34d6657733430164ef67ab2f000fa3d10d51b5 (diff)
downloadgit-75301f90159a505f3683a5eba10174928dc30fb1.zip
git-75301f90159a505f3683a5eba10174928dc30fb1.tar.gz
git-75301f90159a505f3683a5eba10174928dc30fb1.tar.bz2
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 'notes.c')
0 files changed, 0 insertions, 0 deletions