[PATCH] Cygwin: pty: Fix input transfer when multiple non-cygwin apps exist
Takashi Yano
takashi.yano@nifty.ne.jp
Tue Mar 10 08:51:28 GMT 2026
Currently, if two non-cygwin process exist, one is nat pipe owner
and the other is not, and if the second process (not a nat pipe
owner) is terminated first, the first process (the nat pipe owner)
looses the input. This is because transfer_input() is wrongly called
in cleanup_for_non_cygwin_app().
With this patch, in cleanup_for_non_cygwin_app(), transfer_input()
is called only when the current process is a nat pipe owner to
solve this problem.
Fixes: f9542a2e8e75 ("Cygwin: pty: Re-fix the last bug regarding nat-pipe.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by:
---
winsup/cygwin/fhandler/pty.cc | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
index 56b573c8d..aaad47ca9 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -4575,16 +4575,19 @@ fhandler_pty_slave::cleanup_for_non_cygwin_app (handle_set_t *p, tty *ttyp,
{
ttyp->wait_fwd ();
WaitForSingleObject (p->pipe_sw_mutex, INFINITE);
- DWORD switch_to = get_winpid_to_hand_over (ttyp, force_switch_to);
- if ((!switch_to && (ttyp->pcon_activated || stdin_is_ptys))
- && ttyp->pty_input_state_eq (tty::to_nat))
+ if (nat_pipe_owner_self (ttyp->nat_pipe_owner_pid))
{
- WaitForSingleObject (p->input_mutex, mutex_timeout);
- acquire_attach_mutex (mutex_timeout);
- transfer_input (tty::to_cyg, p->from_master_nat, ttyp,
- p->input_available_event);
- release_attach_mutex ();
- ReleaseMutex (p->input_mutex);
+ DWORD switch_to = get_winpid_to_hand_over (ttyp, force_switch_to);
+ if ((!switch_to && (ttyp->pcon_activated || stdin_is_ptys))
+ && ttyp->pty_input_state_eq (tty::to_nat))
+ {
+ WaitForSingleObject (p->input_mutex, mutex_timeout);
+ acquire_attach_mutex (mutex_timeout);
+ transfer_input (tty::to_cyg, p->from_master_nat, ttyp,
+ p->input_available_event);
+ release_attach_mutex ();
+ ReleaseMutex (p->input_mutex);
+ }
}
if (ttyp->pcon_activated)
close_pseudoconsole (ttyp, force_switch_to);
--
2.51.0
More information about the Cygwin-patches
mailing list