From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id BF7263858C83; Sat, 26 Feb 2022 10:53:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF7263858C83 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: pty: Stop to send CTRL_C_EVENT if pcon activated. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 32401ad98ec6f04534f6a60d47566f8c8e500605 X-Git-Newrev: e9d4341677b0594fe98d48e21771827fbedb294d Message-Id: <20220226105312.BF7263858C83@sourceware.org> Date: Sat, 26 Feb 2022 10:53:12 +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: Sat, 26 Feb 2022 10:53:12 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3De9d4341677b= 0594fe98d48e21771827fbedb294d commit e9d4341677b0594fe98d48e21771827fbedb294d Author: Takashi Yano Date: Sat Feb 26 04:19:03 2022 +0900 Cygwin: pty: Stop to send CTRL_C_EVENT if pcon activated. =20 - The commit "Cygwin: console: Redesign handling of special keys." removes special treatment for pty in with pseudo console activated, however, it is necessary on second thought. This is because sending CTRL_C_EVENT to non-cygwin apps will be done in pseudo console, therefore, sending it in fhandler_pty_master::write() duplicates that event for non-cygwin apps. Diff: --- winsup/cygwin/fhandler.h | 2 ++ winsup/cygwin/fhandler_termios.cc | 11 ++++------- winsup/cygwin/fhandler_tty.cc | 11 +++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 0652075b0..fda5a4ec9 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1958,6 +1958,7 @@ class fhandler_termios: public fhandler_base virtual void cleanup_before_exit () {} virtual void setpgid_aux (pid_t pid) {} virtual bool need_console_handler () { return false; } + virtual bool need_send_ctrl_c_event () { return true; } }; =20 enum ansi_intensity @@ -2492,6 +2493,7 @@ public: void get_master_thread_param (master_thread_param_t *p); void get_master_fwd_thread_param (master_fwd_thread_param_t *p); void set_mask_flusho (bool m) { get_ttyp ()->mask_flusho =3D m; } + bool need_send_ctrl_c_event (); }; =20 class fhandler_dev_null: public fhandler_base diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_ter= mios.cc index b236c1b62..568523390 100644 --- a/winsup/cygwin/fhandler_termios.cc +++ b/winsup/cygwin/fhandler_termios.cc @@ -359,16 +359,12 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fh= andler_termios *fh) instead. */ if ((p->process_state & PID_NEW_PG) && (p->process_state & PID_NOTCYGWIN)) - { - GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, - p->dwProcessId); - need_discard_input =3D true; - } - else if (!ctrl_c_event_sent) + GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, p->dwProcessId); + else if ((!fh || fh->need_send_ctrl_c_event () || cyg_leader) + && !ctrl_c_event_sent) { GenerateConsoleCtrlEvent (CTRL_C_EVENT, 0); ctrl_c_event_sent =3D true; - need_discard_input =3D true; } if (resume_pid && fh && !fh->is_console ()) { @@ -377,6 +373,7 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhan= dler_termios *fh) if (::cygheap->ctty && ::cygheap->ctty->is_console ()) init_console_handler (true); } + need_discard_input =3D true; } if (p && p->ctty =3D=3D ttyp->ntty && p->pgid =3D=3D pgid) { diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 2440318b8..9855f54eb 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -4105,3 +4105,14 @@ fhandler_pty_slave::setpgid_aux (pid_t pid) } ReleaseMutex (pcon_mutex); } + +bool +fhandler_pty_master::need_send_ctrl_c_event () +{ + /* If pseudo console is activated, sending CTRL_C_EVENT to non-cygwin + apps will be done in pseudo console, therefore, sending it in + fhandler_pty_master::write() duplicates that event for non-cygwin + apps. So return false if pseudo console is activated. */ + return !(to_be_read_from_pcon () && get_ttyp ()->pcon_activated + && get_ttyp ()->pcon_input_state =3D=3D tty::to_nat); +}