From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 5C0073858C83; Mon, 28 Feb 2022 12:17:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C0073858C83 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: Isolate CTRL_C_EVENTs between ptys. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 8ff9f216fdeca40b0f761fb09458da932dd70027 X-Git-Newrev: 95a28b1f9ed78a873b4bc30e1ffc39ddb23a13a3 Message-Id: <20220228121722.5C0073858C83@sourceware.org> Date: Mon, 28 Feb 2022 12:17:22 +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: Mon, 28 Feb 2022 12:17:22 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D95a28b1f9ed= 78a873b4bc30e1ffc39ddb23a13a3 commit 95a28b1f9ed78a873b4bc30e1ffc39ddb23a13a3 Author: Takashi Yano Date: Mon Feb 28 20:25:09 2022 +0900 Cygwin: pty: Isolate CTRL_C_EVENTs between ptys. =20 - With this patch, unique invisible consoles are created for each pty to isolate CTRL_C_EVENTs between ptys. This is necessary by Ctrl-C handling in fhandler_termios::process_sigs() for non-cygwin apps started in pty if the pseudo console is disabled. Diff: --- winsup/cygwin/fhandler_termios.cc | 6 ++---- winsup/cygwin/fhandler_tty.cc | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_ter= mios.cc index 028210d98..f83770e66 100644 --- a/winsup/cygwin/fhandler_termios.cc +++ b/winsup/cygwin/fhandler_termios.cc @@ -368,8 +368,7 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhan= dler_termios *fh) { FreeConsole (); AttachConsole (p->dwProcessId); - if (::cygheap->ctty && ::cygheap->ctty->is_console ()) - init_console_handler (true); + init_console_handler (true); } if (fh && p =3D=3D myself && being_debugged ()) { /* Avoid deadlock in gdb on console. */ @@ -393,8 +392,7 @@ fhandler_termios::process_sigs (char c, tty* ttyp, fhan= dler_termios *fh) { FreeConsole (); AttachConsole (resume_pid); - if (::cygheap->ctty && ::cygheap->ctty->is_console ()) - init_console_handler (true); + init_console_handler (true); } need_discard_input =3D true; } diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 9855f54eb..dde77ccf2 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -547,6 +547,7 @@ fhandler_pty_master::accept_input () cp_to =3D GetConsoleCP (); FreeConsole (); AttachConsole (resume_pid); + init_console_handler (true); release_attach_mutex (); } else @@ -967,6 +968,12 @@ fhandler_pty_slave::open (int flags, mode_t) this behaviour, protection based on attach_mutex does not take effect. */ get_ttyp ()->need_invisible_console =3D true; + else if (_major (myself->ctty) !=3D DEV_CONS_MAJOR + && (!get_ttyp ()->invisible_console_pid + || !pinfo (get_ttyp ()->invisible_console_pid))) + /* Create a new invisible console for each pty to isolate + CTRL_C_EVENTs between ptys. */ + get_ttyp ()->need_invisible_console =3D true; else fhandler_console::need_invisible (); =20 @@ -1027,6 +1034,7 @@ fhandler_pty_slave::close () fhandler_pty_common::close (); if (!ForceCloseHandle (output_mutex)) termios_printf ("CloseHandle (output_mutex<%p>), %E", output_mutex); + get_ttyp ()->invisible_console_pid =3D 0; return 0; } =20 @@ -1232,12 +1240,14 @@ fhandler_pty_slave::reset_switch_to_pcon (void) 0, TRUE, DUPLICATE_SAME_ACCESS); FreeConsole (); AttachConsole (get_ttyp ()->pcon_pid); + init_console_handler (true); WaitForSingleObject (input_mutex, mutex_timeout); transfer_input (tty::to_cyg, h_pcon_in, get_ttyp (), input_available_event); ReleaseMutex (input_mutex); FreeConsole (); AttachConsole (resume_pid); + init_console_handler (true); CloseHandle (h_pcon_in); } CloseHandle (pcon_owner); @@ -2839,6 +2849,7 @@ fhandler_pty_master::pty_master_fwd_thread (const mas= ter_fwd_thread_param_t *p) cp_from =3D GetConsoleOutputCP (); FreeConsole (); AttachConsole (resume_pid); + init_console_handler (true); release_attach_mutex (); } else @@ -3261,6 +3272,7 @@ fhandler_pty_slave::setup_pseudoconsole (bool nopcon) CloseHandle (pcon_owner); FreeConsole (); AttachConsole (get_ttyp ()->pcon_pid); + init_console_handler (true); goto skip_create; } =20 @@ -3384,6 +3396,7 @@ fhandler_pty_slave::setup_pseudoconsole (bool nopcon) /* Attach to pseudo console */ FreeConsole (); AttachConsole (pi.dwProcessId); + init_console_handler (true); =20 /* Terminate helper process */ SetEvent (goodbye); @@ -3573,6 +3586,7 @@ fhandler_pty_slave::close_pseudoconsole (tty *ttyp, D= WORD force_switch_to) } else AttachConsole (ATTACH_PARENT_PROCESS); + init_console_handler (true); } else { /* Close pseudo console */ @@ -3585,6 +3599,7 @@ fhandler_pty_slave::close_pseudoconsole (tty *ttyp, D= WORD force_switch_to) } else AttachConsole (ATTACH_PARENT_PROCESS); + init_console_handler (true); /* Reconstruct pseudo console handler container here for close */ HPCON_INTERNAL *hp =3D (HPCON_INTERNAL *) HeapAlloc (GetProcessHeap (), 0, @@ -3613,6 +3628,7 @@ fhandler_pty_slave::close_pseudoconsole (tty *ttyp, D= WORD force_switch_to) } else AttachConsole (ATTACH_PARENT_PROCESS); + init_console_handler (true); } } else if (pcon_pid_self (ttyp->pcon_pid)) @@ -3779,6 +3795,7 @@ fhandler_pty_slave::create_invisible_console () /* Detach from console device and create new invisible console. */ FreeConsole(); fhandler_console::need_invisible (true); + init_console_handler (true); get_ttyp ()->need_invisible_console =3D false; get_ttyp ()->invisible_console_pid =3D myself->pid; } @@ -4085,6 +4102,7 @@ fhandler_pty_slave::setpgid_aux (pid_t pid) CloseHandle (pcon_owner); FreeConsole (); AttachConsole (get_ttyp ()->pcon_pid); + init_console_handler (true); attach_restore =3D true; } WaitForSingleObject (input_mutex, mutex_timeout); @@ -4101,6 +4119,7 @@ fhandler_pty_slave::setpgid_aux (pid_t pid) } else AttachConsole (ATTACH_PARENT_PROCESS); + init_console_handler (true); } } ReleaseMutex (pcon_mutex);