From b29fd96cac1df380d2be05892dab35888598186f Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Sun, 8 May 2022 19:45:31 +0900 Subject: [PATCH] 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. --- winsup/cygwin/fhandler_tty.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 484bf55dc..bdde1dce6 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -4171,13 +4171,13 @@ DWORD fhandler_pty_common::attach_console_temporarily (DWORD target_pid) { DWORD resume_pid = 0; + acquire_attach_mutex (mutex_timeout); pinfo pinfo_resume (myself->ppid); if (pinfo_resume) resume_pid = pinfo_resume->dwProcessId; if (!resume_pid) resume_pid = get_console_process_id (myself->dwProcessId, false); bool console_exists = fhandler_console::exists (); - acquire_attach_mutex (mutex_timeout); if (!console_exists || resume_pid) { FreeConsole ();