[PATCH v7 7/7] Cygwin: pty: Drop nat_fg() check from to_be_read_from_nat_pipe()
Takashi Yano
takashi.yano@nifty.ne.jp
Wed Mar 25 13:04:13 GMT 2026
While non-cygwin app exited but the stub process is not terminated
yet, nat_fg() returns false because no non-cygwin app is running.
In this duration, pty input goes cyg pipe. Due to this behaviour,
the key stroke oder is swapped unexpectedly in the following steps.
1) start non-cygwin app
2) press 'a' ('a' goes to nat pipe)
3) non-cygwin app exited
4) press 'b' ('b' goes to cyg pipe)
5) the stub process for non-cygwin app transfers input in nat pipe
to cyg pipe ('a' goes to cyg pipe)
6) the result in the cyg pipe is "ba"
To fix this issue, this patch drops nat_fg() check from
to_be_read_from_nat_pipe(). With this patch, it retunrs true when
(!pcon_start && switch_to_nat_pipe && !masked).
Fixes: f20641789427 ("Cygwin: pty: Reduce unecessary input transfer.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by:
---
winsup/cygwin/fhandler/pty.cc | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
index c7e3ddf50..4187dafce 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -1338,14 +1338,8 @@ fhandler_pty_common::to_be_read_from_nat_pipe (void)
}
while (false);
- if (!pinfo (get_ttyp ()->getpgid ()))
- /* GDB may set invalid process group for non-cygwin process. */
- {
- ret = true;
- goto out;
- }
+ ret = true; /* !pcon_start && switch_to_nat_pipe && !masked */
- ret = get_ttyp ()->nat_fg (get_ttyp ()->getpgid ());
out:
ReleaseMutex (pipe_sw_mutex);
return ret;
@@ -2391,6 +2385,7 @@ fhandler_pty_master::write (const void *ptr, size_t len)
/* This input transfer is needed when cygwin-app which is started from
non-cygwin app is terminated if pseudo console is disabled. */
if (to_be_read_from_nat_pipe () && !get_ttyp ()->pcon_activated
+ && get_ttyp ()->nat_fg (get_ttyp ()->getpgid ())
&& get_ttyp ()->pty_input_state == tty::to_cyg)
{
acquire_attach_mutex (mutex_timeout);
--
2.51.0
More information about the Cygwin-patches
mailing list