From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27256 invoked by alias); 2 Mar 2020 19:26:38 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 27240 invoked by uid 9078); 2 Mar 2020 19:26:38 -0000 Date: Mon, 02 Mar 2020 19:26:00 -0000 Message-ID: <20200302192638.27239.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: console: Fix setting/unsetting xterm mode for input. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 7f5051d76662838103666492a33505e0801c1ee7 X-Git-Newrev: 10d8c2782d79dd5744027e93831dd77aeab452fc X-SW-Source: 2020-q1/txt/msg00098.txt https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=10d8c2782d79dd5744027e93831dd77aeab452fc commit 10d8c2782d79dd5744027e93831dd77aeab452fc Author: Takashi Yano Date: Mon Mar 2 10:12:55 2020 +0900 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(). Diff: --- winsup/cygwin/fhandler_console.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 7c97a78..9c5b801 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -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 ();