[PATCH] Cygwin: console: Release pipe_sw_mutex in pcon_hand_over_proc()
Takashi Yano
takashi.yano@nifty.ne.jp
Wed Mar 25 13:06:33 GMT 2026
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 acuqire input_mutex in set_input_mode() called via
close_ctty(). This deadlock occurs because the pty master
acuires input_mutex first and acuire pipe_sw_mutex next while
the process exiting acuire 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:
---
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 29cdba0d3..1dd5dfa1d 100644
--- a/winsup/cygwin/fhandler/console.cc
+++ b/winsup/cygwin/fhandler/console.cc
@@ -1994,8 +1994,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)
{
@@ -2006,9 +2004,8 @@ fhandler_console::pcon_hand_over_proc (void)
}
else
system_printf("Acquiring pcon_ho_mutex failed.");
+ ReleaseMutex (mtx);
CloseHandle (parent_pty_input_mutex);
- /* Do not release the mutex.
- Hold onto the mutex until this process completes. */
}
bool
--
2.51.0
More information about the Cygwin-patches
mailing list