Skip to content

Commit 84d77e5

Browse files
committed
Cygwin: console: Disable cons_master_thread in win32-input-mode
When win32-input-mode (which is supported by Windows Termainal) is set by "\033[?9001h", cons_master_thread does not work properly and consumes larger and larger memory space. This is because sending event by WriteConsoleInput() is translated into the sequence that is used by win32-input-mode. Due to this behaviour, write-back of the INPUT_RECORDs does not work as expected. With this patch, cons_master_thread is disabled on win32-input-mode where the signal keys such as Ctrl-C, Ctrl-Z etc. never comes. Addresses: https://cygwin.com/pipermail/cygwin/2024-August/256380.html Fixes: ff4440f ("Cygwin: console: Introduce new thread which handles input signal.") Reported-by: Adamyg Mob <[email protected]> Signed-off-by: Takashi Yano <[email protected]>
1 parent a422196 commit 84d77e5

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

winsup/cygwin/fhandler/console.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ fhandler_console::set_input_mode (tty::cons_mode m, const termios *t,
818818
GetConsoleMode (p->input_handle, &oflags);
819819
DWORD flags = oflags
820820
& (ENABLE_EXTENDED_FLAGS | ENABLE_INSERT_MODE | ENABLE_QUICK_EDIT_MODE);
821+
con.curr_input_mode = m;
821822
switch (m)
822823
{
823824
case tty::restore:
@@ -867,6 +868,7 @@ fhandler_console::set_output_mode (tty::cons_mode m, const termios *t,
867868
if (con.orig_virtual_terminal_processing_mode)
868869
flags |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
869870
WaitForSingleObject (p->output_mutex, mutex_timeout);
871+
con.curr_output_mode = m;
870872
switch (m)
871873
{
872874
case tty::restore:
@@ -1109,12 +1111,12 @@ fhandler_console::bg_check (int sig, bool dontsignal)
11091111
/* Setting-up console mode for cygwin app. This is necessary if the
11101112
cygwin app and other non-cygwin apps are started simultaneously
11111113
in the same process group. */
1112-
if (sig == SIGTTIN)
1114+
if (sig == SIGTTIN && con.curr_input_mode != tty::cygwin)
11131115
{
11141116
set_input_mode (tty::cygwin, &tc ()->ti, get_handle_set ());
11151117
set_disable_master_thread (false, this);
11161118
}
1117-
if (sig == SIGTTOU)
1119+
if (sig == SIGTTOU && con.curr_output_mode != tty::cygwin)
11181120
set_output_mode (tty::cygwin, &tc ()->ti, get_handle_set ());
11191121

11201122
return fhandler_termios::bg_check (sig, dontsignal);
@@ -2921,6 +2923,8 @@ fhandler_console::char_command (char c)
29212923
}
29222924
if (con.args[i] == 1) /* DECCKM */
29232925
con.cursor_key_app_mode = (c == 'h');
2926+
if (con.args[i] == 9001) /* win32-input-mode (https://github.com/microsoft/terminal/blob/main/doc/specs/%234999%20-%20Improved%20keyboard%20handling%20in%20Conpty.md) */
2927+
set_disable_master_thread (c == 'h', this);
29242928
}
29252929
/* Call fix_tab_position() if screen has been alternated. */
29262930
if (need_fix_tab_position)

winsup/cygwin/local_includes/fhandler.h

+2
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,8 @@ class dev_console
21712171
char *cons_rapoi;
21722172
bool cursor_key_app_mode;
21732173
bool disable_master_thread;
2174+
tty::cons_mode curr_input_mode;
2175+
tty::cons_mode curr_output_mode;
21742176
bool master_thread_suspended;
21752177
int num_processed; /* Number of input events in the current input buffer
21762178
already processed by cons_master_thread(). */

winsup/cygwin/release/3.5.5

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fixes:
2+
------
3+
4+
- Fix undesired behaviour of console master thread in win32-input-mode
5+
which is supported by Windows Termainal.
6+
Addresses: https://cygwin.com/pipermail/cygwin/2024-August/256380.html

0 commit comments

Comments
 (0)