From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 0A3C63858419; Tue, 14 Dec 2021 10:29:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A3C63858419 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 conditions for input transfer again. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 720234b78afb4a972c3cea4ae22d181ea83568cc X-Git-Newrev: 0795f704f750e4b441aa256b1b849e4ebe3af684 Message-Id: <20211214102914.0A3C63858419@sourceware.org> Date: Tue, 14 Dec 2021 10:29:14 +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: Tue, 14 Dec 2021 10:29:14 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=0795f704f750e4b441aa256b1b849e4ebe3af684 commit 0795f704f750e4b441aa256b1b849e4ebe3af684 Author: Takashi Yano Date: Tue Dec 14 19:20:34 2021 +0900 Cygwin: pty: Fix conditions for input transfer again. Diff: --- winsup/cygwin/fhandler_tty.cc | 67 +++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 5e76b51c5..ee687d9ad 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -1181,37 +1181,48 @@ fhandler_pty_slave::reset_switch_to_pcon (void) && pcon_pid_alive (get_ttyp ()->pcon_pid)) { /* There is a process which is grabbing pseudo console. */ - if (!to_be_read_from_pcon () && get_ttyp ()->pcon_activated + if (!to_be_read_from_pcon () && get_ttyp ()->pcon_input_state_eq (tty::to_nat)) { - HANDLE pcon_owner = - OpenProcess (PROCESS_DUP_HANDLE, FALSE, get_ttyp ()->pcon_pid); - if (pcon_owner) + if (get_ttyp ()->pcon_activated) { - pinfo pinfo_resume = pinfo (myself->ppid); - DWORD resume_pid; - if (pinfo_resume) - resume_pid = pinfo_resume->dwProcessId; - else - resume_pid = - get_console_process_id (myself->dwProcessId, false); - if (resume_pid) + HANDLE pcon_owner = + OpenProcess (PROCESS_DUP_HANDLE, FALSE, get_ttyp ()->pcon_pid); + if (pcon_owner) { - HANDLE h_pcon_in; - DuplicateHandle (pcon_owner, get_ttyp ()->h_pcon_in, - GetCurrentProcess (), &h_pcon_in, - 0, TRUE, DUPLICATE_SAME_ACCESS); - FreeConsole (); - AttachConsole (get_ttyp ()->pcon_pid); - WaitForSingleObject (input_mutex, INFINITE); - transfer_input (tty::to_cyg, h_pcon_in, get_ttyp (), - input_available_event); - ReleaseMutex (input_mutex); - FreeConsole (); - AttachConsole (resume_pid); - CloseHandle (h_pcon_in); + pinfo pinfo_resume = pinfo (myself->ppid); + DWORD resume_pid; + if (pinfo_resume) + resume_pid = pinfo_resume->dwProcessId; + else + resume_pid = + get_console_process_id (myself->dwProcessId, false); + if (resume_pid) + { + HANDLE h_pcon_in; + DuplicateHandle (pcon_owner, get_ttyp ()->h_pcon_in, + GetCurrentProcess (), &h_pcon_in, + 0, TRUE, DUPLICATE_SAME_ACCESS); + FreeConsole (); + AttachConsole (get_ttyp ()->pcon_pid); + WaitForSingleObject (input_mutex, INFINITE); + transfer_input (tty::to_cyg, h_pcon_in, get_ttyp (), + input_available_event); + ReleaseMutex (input_mutex); + FreeConsole (); + AttachConsole (resume_pid); + CloseHandle (h_pcon_in); + } + CloseHandle (pcon_owner); } - CloseHandle (pcon_owner); + } + else if (!get_ttyp ()->pcon_fg (get_ttyp ()->getpgid ()) + && get_ttyp ()->switch_to_pcon_in) + { + WaitForSingleObject (input_mutex, INFINITE); + transfer_input (tty::to_cyg, get_handle_nat (), get_ttyp (), + input_available_event); + ReleaseMutex (input_mutex); } } ReleaseMutex (pcon_mutex); @@ -1287,8 +1298,8 @@ fhandler_pty_slave::mask_switch_to_pcon_in (bool mask, bool xfer) /* This is needed when cygwin-app is started from non-cygwin app if pseudo console is disabled. */ - bool need_xfer = - get_ttyp ()->switch_to_pcon_in && !get_ttyp ()->pcon_activated; + bool need_xfer = get_ttyp ()->pcon_fg (get_ttyp ()->getpgid ()) + && get_ttyp ()->switch_to_pcon_in && !get_ttyp ()->pcon_activated; /* In GDB, transfer input based on setpgid() does not work because GDB may not set terminal process group properly. Therefore,