Skip to content

Commit 41e6325

Browse files
dschotyan0
andcommitted
Cygwin: console: re-enable the master thread before selecting cygwin input mode
When a cygwin program and a non-cygwin program run in the same foreground process group (for example the pipeline `cat | ping`), Ctrl-C stopped interrupting the cygwin program after "Cygwin: console: Ensure the master thread runs only when it is supposed to". The console only delivers Ctrl-C as a raw 0x03 byte (which the console master thread reads and turns into a SIGINT for the foreground process group) while that thread is live. When it is suspended or disabled, set_input_mode (tty::cygwin) instead requests ENABLE_PROCESSED_INPUT, so the console raises a CTRL_C_EVENT and the 0x03 byte never reaches the master thread. The referenced commit reordered the two explicit enable paths, bg_check () and post_open_setup (), and one path which normally(*1) enables master thread, clearnup_for_non_cygwin_app(), so that set_input_mode (tty::cygwin) runs while disable_master_thread is still set; that leaves ENABLE_PROCESSED_INPUT on and the cygwin program never receives its SIGINT. (*1 ... except the process which calls exec() for non-cygwin app while itself is the cons master. In this case, subsequent set_input_mode() call sets the mode to tty::restore, and the master thread should be kept 'disabled' until the process exits.) Clear disable_master_thread before selecting cygwin input mode in those two paths, so the mode is configured with the master thread already live and ENABLE_PROCESSED_INPUT stays off. The disable paths and the synchronous suspension that the referenced commit added are left unchanged, so non-cygwin programs still get the master thread reliably suspended. Fixes: 733d5a9 ("Cygwin: console: Ensure the master thread runs only when it is supposed to") Assisted-by: Opus 4.8 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Co-Authored-by: Takashi Yano <takashi.yano@nifty.ne.jp> Reviewed-by: Takashi Yano <takashi.yano@nifty.ne.jp>
1 parent 2047a73 commit 41e6325

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

winsup/cygwin/fhandler/console.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,14 +991,14 @@ fhandler_console::cleanup_for_non_cygwin_app (handle_set_t *p)
991991
termios *ti = shared_console_info[unit] ?
992992
&(shared_console_info[unit]->tty_min_state.ti) : &dummy;
993993
/* Cleaning-up console mode for non-cygwin app. */
994+
set_disable_master_thread (con.owner == GetCurrentProcessId ());
994995
/* conmode can be tty::restore when non-cygwin app is
995996
exec'ed from login shell. */
996997
tty::cons_mode conmode = cons_mode_on_close (p);
997998
if (con.curr_output_mode != conmode)
998999
set_output_mode (conmode, ti, p);
9991000
if (con.curr_input_mode != conmode)
10001001
set_input_mode (conmode, ti, p);
1001-
set_disable_master_thread (con.owner == GetCurrentProcessId ());
10021002
}
10031003

10041004
/* Return the tty structure associated with a given tty number. If the
@@ -1191,8 +1191,8 @@ fhandler_console::bg_check (int sig, bool dontsignal)
11911191
in the same process group. */
11921192
if (sig == SIGTTIN && con.curr_input_mode != tty::cygwin)
11931193
{
1194-
set_input_mode (tty::cygwin, &tc ()->ti, get_handle_set ());
11951194
set_disable_master_thread (false, this);
1195+
set_input_mode (tty::cygwin, &tc ()->ti, get_handle_set ());
11961196
}
11971197
if (sig == SIGTTOU && con.curr_output_mode != tty::cygwin)
11981198
set_output_mode (tty::cygwin, &tc ()->ti, get_handle_set ());
@@ -2111,8 +2111,8 @@ fhandler_console::post_open_setup (int fd)
21112111
/* Setting-up console mode for cygwin app started from non-cygwin app. */
21122112
if (fd == 0)
21132113
{
2114-
set_input_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);
21152114
set_disable_master_thread (false, this);
2115+
set_input_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);
21162116
}
21172117
else if (fd == 1 || fd == 2)
21182118
set_output_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);

0 commit comments

Comments
 (0)