aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2022-05-08 17:48:06 +0900
committerTakashi Yano <takashi.yano@nifty.ne.jp>2022-05-08 18:00:21 +0900
commitac2f7f888c3eba20941f5e0cc1c4bb5fd523e730 (patch)
treeb48c90c008d6b7b93b13cad105042eab88f6de64 /winsup
parent5c7d81b75ea8dae64afb56e38c49063d5776fab9 (diff)
downloadnewlib-ac2f7f888c3eba20941f5e0cc1c4bb5fd523e730.zip
newlib-ac2f7f888c3eba20941f5e0cc1c4bb5fd523e730.tar.gz
newlib-ac2f7f888c3eba20941f5e0cc1c4bb5fd523e730.tar.bz2
Cygwin: pty: Fix acquiring attach_mutex timing.
- When temporarily attaching a console, the timing of acquiring attach_mutex was not appropriate. This sometimes caused master forwarding thread to crash on Ctrl-C in Windows 7. This patch fixes the issue.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/fhandler_termios.cc2
-rw-r--r--winsup/cygwin/fhandler_tty.cc12
2 files changed, 7 insertions, 7 deletions
diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_termios.cc
index 0d53ad2..0bc3600 100644
--- a/winsup/cygwin/fhandler_termios.cc
+++ b/winsup/cygwin/fhandler_termios.cc
@@ -359,6 +359,7 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_termios *fh)
CTRL_C_EVENT. After sending the event, reattach to the
console to which the process was previously attached. */
bool console_exists = fhandler_console::exists ();
+ acquire_attach_mutex (mutex_timeout);
pinfo pinfo_resume = pinfo (myself->ppid);
DWORD resume_pid = 0;
if (pinfo_resume)
@@ -366,7 +367,6 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhandler_termios *fh)
else
resume_pid = fhandler_pty_common::get_console_process_id
(myself->dwProcessId, false);
- acquire_attach_mutex (mutex_timeout);
if ((!console_exists || resume_pid) && fh && !fh->is_console ())
{
FreeConsole ();
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index c91f400..b9cc973 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -533,6 +533,7 @@ fhandler_pty_master::accept_input ()
DWORD target_pid = 0;
if (pinfo_target)
target_pid = pinfo_target->dwProcessId;
+ acquire_attach_mutex (mutex_timeout);
pinfo pinfo_resume = pinfo (myself->ppid);
DWORD resume_pid;
if (pinfo_resume)
@@ -544,7 +545,6 @@ fhandler_pty_master::accept_input ()
{
/* Slave attaches to a different console than master.
Therefore reattach here. */
- acquire_attach_mutex (mutex_timeout);
FreeConsole ();
AttachConsole (target_pid);
cp_to = GetConsoleCP ();
@@ -552,10 +552,10 @@ fhandler_pty_master::accept_input ()
if (resume_pid && console_exists)
AttachConsole (resume_pid);
init_console_handler (false);
- release_attach_mutex ();
}
else
cp_to = GetConsoleCP ();
+ release_attach_mutex ();
if (get_ttyp ()->term_code_page != cp_to)
{
@@ -1244,6 +1244,7 @@ fhandler_pty_slave::reset_switch_to_pcon (void)
OpenProcess (PROCESS_DUP_HANDLE, FALSE, get_ttyp ()->pcon_pid);
if (pcon_owner)
{
+ acquire_attach_mutex (mutex_timeout);
pinfo pinfo_resume = pinfo (myself->ppid);
DWORD resume_pid;
if (pinfo_resume)
@@ -1257,7 +1258,6 @@ fhandler_pty_slave::reset_switch_to_pcon (void)
DuplicateHandle (pcon_owner, get_ttyp ()->h_pcon_in,
GetCurrentProcess (), &h_pcon_in,
0, TRUE, DUPLICATE_SAME_ACCESS);
- acquire_attach_mutex (mutex_timeout);
FreeConsole ();
AttachConsole (get_ttyp ()->pcon_pid);
init_console_handler (false);
@@ -1268,9 +1268,9 @@ fhandler_pty_slave::reset_switch_to_pcon (void)
FreeConsole ();
AttachConsole (resume_pid);
init_console_handler (false);
- release_attach_mutex ();
CloseHandle (h_pcon_in);
}
+ release_attach_mutex ();
CloseHandle (pcon_owner);
}
}
@@ -2878,6 +2878,7 @@ fhandler_pty_master::pty_master_fwd_thread (const master_fwd_thread_param_t *p)
DWORD target_pid = 0;
if (pinfo_target)
target_pid = pinfo_target->dwProcessId;
+ acquire_attach_mutex (mutex_timeout);
pinfo pinfo_resume = pinfo (myself->ppid);
DWORD resume_pid;
if (pinfo_resume)
@@ -2889,7 +2890,6 @@ fhandler_pty_master::pty_master_fwd_thread (const master_fwd_thread_param_t *p)
{
/* Slave attaches to a different console than master.
Therefore reattach here. */
- acquire_attach_mutex (mutex_timeout);
FreeConsole ();
AttachConsole (target_pid);
cp_from = GetConsoleOutputCP ();
@@ -2897,10 +2897,10 @@ fhandler_pty_master::pty_master_fwd_thread (const master_fwd_thread_param_t *p)
if (resume_pid && console_exists)
AttachConsole (resume_pid);
init_console_handler (false);
- release_attach_mutex ();
}
else
cp_from = GetConsoleOutputCP ();
+ release_attach_mutex ();
if (p->ttyp->term_code_page != cp_from)
{