[newlib-cygwin/cygwin-3_6-branch] Cygwin: console: Release pipe_sw_mutex in pcon_hand_over_proc()
Takashi Yano
tyan0@sourceware.org
Thu Mar 26 11:36:20 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c641981e99c5d2d198217b842420129ff3f9efd9
commit c641981e99c5d2d198217b842420129ff3f9efd9
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date: Tue Mar 24 11:25:40 2026 +0900
Cygwin: console: Release pipe_sw_mutex in pcon_hand_over_proc()
Currently, pipe_sw_mutex is held in the process which is running
in console inherited from pseudo console until the process ends.
Due to this behaviour, the process may cause deadlock when it
attempts to acquire input_mutex in set_input_mode() called via
close_ctty(). This deadlock occurs because the pty master
acquire input_mutex first and acquire pipe_sw_mutex next while
the process exiting acquire pipe_sw_mutex first.
To avoid this deadlock, this patch releases pipe_sw_mutex in
pcon_hand_over_proc(). In addition, pointless pipe_sw_mutex
acquire/release is drppped in pcon_hand_over_proc().
Fixes: 04f386e9af99 ("Cygwin: console: Inherit pcon hand over from parent pty")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
(cherry picked from commit 9ef8e3ad3bec51afddb26e472857962bd1b028e3)
Diff:
---
winsup/cygwin/fhandler/console.cc | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc
index 831df4f2c..9e116118a 100644
--- a/winsup/cygwin/fhandler/console.cc
+++ b/winsup/cygwin/fhandler/console.cc
@@ -1946,8 +1946,6 @@ fhandler_console::pcon_hand_over_proc (void)
char buf[MAX_PATH];
shared_name (buf, PIPE_SW_MUTEX, parent_pty);
HANDLE mtx = OpenMutex (MAXIMUM_ALLOWED, FALSE, buf);
- WaitForSingleObject (mtx, INFINITE);
- ReleaseMutex (mtx);
DWORD res = WaitForSingleObject (mtx, INFINITE);
if (res == WAIT_OBJECT_0 || res == WAIT_ABANDONED)
{
@@ -1958,8 +1956,7 @@ fhandler_console::pcon_hand_over_proc (void)
}
else
system_printf("Acquiring pcon_ho_mutex failed.");
- /* Do not release the mutex.
- Hold onto the mutex until this process completes. */
+ ReleaseMutex (mtx);
}
bool
More information about the Cygwin-cvs
mailing list