Cygwin: console: Fix setting/unsetting xterm mode for input.

- This patch fixes the issue that xterm compatible mode for input
  is not correctly set/unset in some situation such as:
   1) cat is stopped by ctrl-c.
   2) The window size is changed in less.
  In case 1), request_xterm_mode_input(true) is called in read(),
  however, cat is stopped without request_xterm_mode_input(false).
  In case 2), less uses longjmp in signal handler, therefore,
  corresponding request_xterm_mode_input(false) is not called if
  the SIGWINCH signal is sent within read(). With this patch,
  InterlockedExchange() is used instead of InterlockedIncrement/
  Decrement().
This commit is contained in:
Takashi Yano 2020-03-02 10:12:55 +09:00 committed by Corinna Vinschen
parent 7f5051d766
commit 10d8c2782d
1 changed files with 3 additions and 2 deletions

View File

@ -267,7 +267,7 @@ fhandler_console::request_xterm_mode_input (bool req)
return;
if (req)
{
if (InterlockedIncrement (&con.xterm_mode_input) == 1)
if (InterlockedExchange (&con.xterm_mode_input, 1) == 0)
{
DWORD dwMode;
GetConsoleMode (get_handle (), &dwMode);
@ -277,7 +277,7 @@ fhandler_console::request_xterm_mode_input (bool req)
}
else
{
if (InterlockedDecrement (&con.xterm_mode_input) == 0)
if (InterlockedExchange (&con.xterm_mode_input, 0) == 1)
{
DWORD dwMode;
GetConsoleMode (get_handle (), &dwMode);
@ -1171,6 +1171,7 @@ fhandler_console::close ()
if ((NT_SUCCESS (status) && obi.HandleCount == 1)
|| myself->pid == con.owner)
request_xterm_mode_output (false);
request_xterm_mode_input (false);
}
release_output_mutex ();