From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Cygwin: pty: Fix input switching failure.
Date: Wed, 15 Dec 2021 12:29:48 +0900 [thread overview]
Message-ID: <20211215032948.527-1-takashi.yano@nifty.ne.jp> (raw)
- This patch fixes the failure of input switching between io_handle
and io_handle_nat. This very rarely happens, however, input is
wrongly switched to io_handle_nat even though the non-cygwin app
is in the background.
---
winsup/cygwin/fhandler_tty.cc | 3 +++
winsup/cygwin/tty.cc | 3 ++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index ee687d9ad..c8ad53cb7 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -1056,6 +1056,7 @@ fhandler_pty_slave::set_switch_to_pcon (void)
isHybrid = true;
setup_locale ();
myself->exec_dwProcessId = myself->dwProcessId;
+ myself->process_state |= PID_NEW_PG; /* Marker for pcon_fg */
bool nopcon = (disable_pcon || !term_has_pcon_cap (NULL));
WaitForSingleObject (pcon_mutex, INFINITE);
bool pcon_enabled = setup_pseudoconsole (nopcon);
@@ -1168,6 +1169,7 @@ fhandler_pty_slave::reset_switch_to_pcon (void)
}
}
myself->exec_dwProcessId = 0;
+ myself->process_state &= ~PID_NEW_PG;
isHybrid = false;
}
}
@@ -2272,6 +2274,7 @@ fhandler_pty_master::write (const void *ptr, size_t len)
_pinfo *p = pids[i];
if (p->ctty == get_ttyp ()->ntty
&& p->pgid == get_ttyp ()->getpgid ()
+ && (p->process_state & PID_NOTCYGWIN)
&& (p->process_state & PID_NEW_PG))
{
wpid = p->dwProcessId;
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index 2566f4c45..11ad3ec51 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -392,7 +392,8 @@ tty::pcon_fg (pid_t pgid)
for (unsigned i = 0; i < pids.npids; i++)
{
_pinfo *p = pids[i];
- if (p->ctty == ntty && p->pgid == pgid && p->exec_dwProcessId)
+ if (p->ctty == ntty && p->pgid == pgid
+ && (p->process_state & (PID_NOTCYGWIN | PID_NEW_PG)))
return true;
}
if (pgid > MAX_PID)
--
2.34.1
reply other threads:[~2021-12-15 3:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211215032948.527-1-takashi.yano@nifty.ne.jp \
--to=takashi.yano@nifty.ne.jp \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).