From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Cygwin: pty: Fix conditions for input transfer again.
Date: Tue, 14 Dec 2021 19:23:17 +0900 [thread overview]
Message-ID: <20211214102317.657-1-takashi.yano@nifty.ne.jp> (raw)
---
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,
--
2.34.1
reply other threads:[~2021-12-14 10:23 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=20211214102317.657-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).