From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 6BB3D3858C3A; Wed, 15 Dec 2021 03:30:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BB3D3858C3A Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: pty: Fix input switching failure. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 0795f704f750e4b441aa256b1b849e4ebe3af684 X-Git-Newrev: 80f4b7d5456ea17d64998805fb3d64db091201fc Message-Id: <20211215033027.6BB3D3858C3A@sourceware.org> Date: Wed, 15 Dec 2021 03:30:27 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Dec 2021 03:30:27 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=80f4b7d5456ea17d64998805fb3d64db091201fc commit 80f4b7d5456ea17d64998805fb3d64db091201fc Author: Takashi Yano Date: Wed Dec 15 12:25:58 2021 +0900 Cygwin: pty: Fix input switching failure. - 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. Diff: --- 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)