From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 09DF03858C41; Thu, 1 Jun 2023 11:16:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09DF03858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685618204; bh=7vD+Jc6/W/ia7/7tpCwxmGU3mpk743c4phTQ3TrW4sQ=; h=From:To:Subject:Date:From; b=AMEnZHSZq4F6JznzDm2qDv6u5iJkS/gGj6Kk1HDxRSy7JoOtwhGo497E65JlMfIlM LBynAjF0jJ7u4/MRE761ucgfec244eQko9qRkjuCMv7UFc1z4hdv+z0CtPS9H1/UYJ UQ1dI+SXjaXJpwv/SqBRFT804jLEst1L3xMNp9BY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_4-branch] Cygwin: pty: Fix transferring type-ahead input between input pipes. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_4-branch X-Git-Oldrev: deca777a958cad67faa73d7457ecccd8c73ed943 X-Git-Newrev: 3456e8b7db5b37cf9e10aedbbf552df10f75e055 Message-Id: <20230601111644.09DF03858C41@sourceware.org> Date: Thu, 1 Jun 2023 11:16:44 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D3456e8b7db5= b37cf9e10aedbbf552df10f75e055 commit 3456e8b7db5b37cf9e10aedbbf552df10f75e055 Author: Takashi Yano Date: Thu Jun 1 19:44:41 2023 +0900 Cygwin: pty: Fix transferring type-ahead input between input pipes. =20 After the commit 595fcb21ffc0, transferring type-ahead input between the pipe for cygwin app and the pipe for non-cygwin app will not be done appropriately when the stdin of the non-cygwin app is not pty. Due to this issue, sometimes the keyboard input might be lost which should be sent to cygwin app. This patch fixes the issue. =20 Fixes: 595fcb21ffc0 ("Cygwin: pty: Fix reading CONIN$ when stdin is not= a pty.") Signed-off-by: Takashi Yano Diff: --- winsup/cygwin/fhandler/pty.cc | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc index aa7ceb0ba..9ca3b64b6 100644 --- a/winsup/cygwin/fhandler/pty.cc +++ b/winsup/cygwin/fhandler/pty.cc @@ -1298,17 +1298,7 @@ fhandler_pty_slave::mask_switch_to_nat_pipe (bool ma= sk, bool xfer) else if (InterlockedDecrement (&num_reader) =3D=3D 0) CloseHandle (slave_reading); =20 - /* This is needed when cygwin-app is started from non-cygwin app if - pseudo console is disabled. */ - bool need_xfer =3D get_ttyp ()->nat_fg (get_ttyp ()->getpgid ()) - && get_ttyp ()->switch_to_nat_pipe && !get_ttyp ()->pcon_activated; - - /* In GDB, transfer input based on setpgid() does not work because - GDB may not set terminal process group properly. Therefore, - transfer input here if isHybrid is set. */ - bool need_gdb_xfer =3D - isHybrid && GetStdHandle (STD_INPUT_HANDLE) =3D=3D get_handle (); - if (!!masked !=3D mask && xfer && (need_gdb_xfer || need_xfer)) + if (!!masked !=3D mask && xfer && get_ttyp ()->switch_to_nat_pipe) { if (mask && get_ttyp ()->pty_input_state_eq (tty::to_nat)) { @@ -2240,11 +2230,7 @@ fhandler_pty_master::write (const void *ptr, size_t = len) if (!get_ttyp ()->pcon_start) { /* Pseudo console initialization has been done in above code. */ pinfo pp (get_ttyp ()->pcon_start_pid); - bool pcon_fg =3D (pp && get_ttyp ()->getpgid () =3D=3D pp->pgid); - /* GDB may set WINPID rather than cygwin PID to process group - when the debugged process is a non-cygwin process.*/ - pcon_fg |=3D !pinfo (get_ttyp ()->getpgid ()); - if (get_ttyp ()->switch_to_nat_pipe && pcon_fg + if (get_ttyp ()->switch_to_nat_pipe && get_ttyp ()->pty_input_state_eq (tty::to_cyg)) { /* This accept_input() call is needed in order to transfer input @@ -4142,7 +4128,7 @@ fhandler_pty_slave::cleanup_for_non_cygwin_app (handl= e_set_t *p, tty *ttyp, DWORD force_switch_to) { ttyp->wait_fwd (); - if (ttyp->getpgid () =3D=3D myself->pgid && stdin_is_ptys + if ((ttyp->pcon_activated || stdin_is_ptys) && ttyp->pty_input_state_eq (tty::to_nat)) { WaitForSingleObject (p->input_mutex, mutex_timeout);