git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/1] Fix a long-standing isatty() problem on Windows

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 11, 2016, 11:16 UTC
Message-ID
<cover.1481454992.git.johannes.schindelin@gmx.de>

I finally got a chance to debug the problems with the ever-timing-out test runs of `pu` on Windows. Turns out that pb/bisect uncovered a really old, really bad bug: on Windows, isatty() does not do what Git expects, at least not completely: it detects interactive terminals *and character devices*.

Why is this such a big deal?

One such character device is NUL, Windows' equivalent of /dev/null. And guess what happens when the new tests of the bisect--helper run, with stdin redirected from /dev/null? Precisely. Git asks "the user" for reassurance that it may really continue, waiting forever. Or for Ctrl+C.

As we know what Git's source code wants, we have to make extra certain to test whether isatty() reports success for a Console. The common way to do this is to run GetConsoleMode() for input file descriptors, and GetConsoleScreenBufferInfo() for output file descriptors.

One additional note: the new winansi_isatty() function was put into this particular spot not only because it vaguely makes sense to put tty-related stuff into compat/winansi.c, but with required future changes in mind:

The current way in which Git for Windows makes sure that isatty() returns non-zero for Git Bash (which runs in a terminal emulator called MinTTY that does *not* have any Windows Console associated with it, and therefore Windows' _isatty() would actually return 0 if it was not for our detect_msys_tty() function) is hacky and needs to be fixed properly.

It is hacky because it relies on internals of the MSVC runtime that do not hold true for the new Universal runtimes, which are used when compiling with Visual C.

We already have experimental code to future-proof this method, and we use that already when compiling Git for Windows in Visual Studio.

The place in which winansi_isatty() now lives will hopefully make it possible to unify the code paths again, so that both GCC and Visual C use detect_msys_tty() through winansi_isatty().

This will also fix a bug where current Visual C-built Git may misdetect a reopened stdin to be connected to an interactive terminal.

Johannes Schindelin (1):
  mingw: intercept isatty() to handle /dev/null as Git expects it
 compat/mingw.h   |  3 +++
 compat/winansi.c | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
base-commit: 8d7a455ed52e2a96debc080dfc011b6bb00db5d2
Published-As: https://github.com/dscho/git/releases/tag/mingw-isatty-v1
Fetch-It-Via: git fetch https://github.com/dscho/git mingw-isatty-v1
-- 
2.11.0.rc3.windows.1
Next: Johannes Schindelin
Message 1 of 21 in “Fix a long-standing isatty() problem on Windows”
  1. 0/1 Fix a long-standing isatty() problem on WindowsJohannes Schindelin, Dec 11, 2016
  2. 1/1 mingw: intercept isatty() to handle /dev/null as Git expects itJohannes Schindelin, Dec 11, 2016
  3. Johannes SixtDec 16, 2016
  4. Junio C HamanoDec 16, 2016
  5. Johannes SixtDec 16, 2016
  6. Junio C HamanoDec 16, 2016
  7. Johannes SchindelinDec 21, 2016
  8. winansi_isatty(): fix when Git is used from CMDJohannes Sixt, Dec 18, 2016
  9. Johannes SixtDec 18, 2016
  10. Johannes SixtDec 19, 2016
  11. Johannes SchindelinDec 21, 2016
  12. Johannes SchindelinDec 20, 2016
  13. Junio C HamanoDec 19, 2016
  14. Johannes SchindelinDec 20, 2016
  15. Junio C HamanoDec 20, 2016
  16. Johannes SchindelinDec 21, 2016
  17. Junio C HamanoDec 21, 2016
  18. Johannes SchindelinDec 22, 2016
  19. Junio C HamanoDec 11, 2016
  20. Johannes SchindelinDec 12, 2016
  21. Junio C HamanoDec 12, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.