Win32: fix broken pipe detection
commit1b12cb06ffd8a73a3d42f5df7fb7e76e1f868361
authorKarsten Blees <blees@dcon.de>
Thu, 1 Mar 2012 20:53:54 +0000 (1 21:53 +0100)
committerJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 11 May 2012 22:50:04 +0000 (11 17:50 -0500)
treef65d2c4f55f85a3a8f9c531e4d70eee7c18a0bef
parent71178fe7e8180cb98faed345dfa7437701e89ec7
Win32: fix broken pipe detection

As of "Win32: Thread-safe windows console output", git-log no longer
terminates when the pager process dies. This is due to disabling buffering
for the replaced stdout / stderr streams. Git-log will periodically fflush
stdout (see write_or_die.c/mayble_flush_or_die()), but with no buffering,
this is a NOP that always succeeds (so we never detect the EPIPE error).

Exchange the original console handles with our console thread pipe handles
by accessing the internal MSVCRT data structures directly (which are
exposed via __pioinfo for some reason).

Implement this with minimal assumptions about the actual data structure to
make it work with different (hopefully even future) MSVCRT versions.

While messing with internal data structures is ugly, this patch solves the
problem at the source instead of adding more workarounds. We no longer need
the special winansi_isatty override, and the limitations documented in
"Win32: Thread-safe windows console output" are gone (i.e. fdopen(1/2)
returns unbuffered streams now, and isatty() for duped console file
descriptors works as expected).

Signed-off-by: Karsten Blees <blees@dcon.de>
compat/mingw.h
compat/winansi.c