From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 82373385801E; Fri, 4 Mar 2022 11:09:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82373385801E 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: Rearrange reset_switch_to_nat_pipe() calls. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: a263b94b5efd4595bf72425a975a8e29fcc989de X-Git-Newrev: e93c7cb571f20a79efd561d430ab4cb38e01a635 Message-Id: <20220304110923.82373385801E@sourceware.org> Date: Fri, 4 Mar 2022 11:09:23 +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: Fri, 04 Mar 2022 11:09:23 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3De93c7cb571f= 20a79efd561d430ab4cb38e01a635 commit e93c7cb571f20a79efd561d430ab4cb38e01a635 Author: Takashi Yano Date: Fri Mar 4 14:42:46 2022 +0900 Cygwin: pty: Rearrange reset_switch_to_nat_pipe() calls. =20 - Previously, reset_switch_to_nat_pipe() is called from many places in pty code. This patch reorganizes that. With this patch, it is called only from bg_check() and setpgid_aux(). The calls which does not have enough reason have been omitted. Diff: --- winsup/cygwin/fhandler.h | 1 + winsup/cygwin/fhandler_tty.cc | 22 ++++++++++------------ winsup/cygwin/select.cc | 2 -- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index c32dc7b57..e7cf17df0 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -2378,6 +2378,7 @@ class fhandler_pty_slave: public fhandler_pty_common select_record *select_read (select_stuff *); select_record *select_write (select_stuff *); select_record *select_except (select_stuff *); + bg_check_types bg_check (int sig, bool dontsignal =3D false); virtual char const *ttyname () { return pc.dev.name (); } int __reg2 fstat (struct stat *buf); int __reg3 facl (int, int, struct acl *); diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index b96a7b3cf..76c5e2413 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -1287,8 +1287,6 @@ fhandler_pty_slave::write (const void *ptr, size_t le= n) =20 push_process_state process_state (PID_TTYOU); =20 - reset_switch_to_nat_pipe (); - acquire_output_mutex (mutex_timeout); if (!process_opost_output (get_output_handle (), ptr, towrite, false, get_ttyp (), is_nonblocking ())) @@ -1409,10 +1407,7 @@ fhandler_pty_slave::read (void *ptr, size_t& len) push_process_state process_state (PID_TTYIN); =20 if (ptr) /* Indicating not tcflush(). */ - { - mask_switch_to_nat_pipe (true, true); - reset_switch_to_nat_pipe (); - } + mask_switch_to_nat_pipe (true, true); =20 if (is_nonblocking () || !ptr) /* Indicating tcflush(). */ time_to_wait =3D 0; @@ -1669,7 +1664,6 @@ fhandler_pty_master::dup (fhandler_base *child, int) int fhandler_pty_slave::tcgetattr (struct termios *t) { - reset_switch_to_nat_pipe (); *t =3D get_ttyp ()->ti; =20 /* Workaround for rlwrap */ @@ -1690,7 +1684,6 @@ fhandler_pty_slave::tcgetattr (struct termios *t) int fhandler_pty_slave::tcsetattr (int, const struct termios *t) { - reset_switch_to_nat_pipe (); acquire_output_mutex (mutex_timeout); get_ttyp ()->ti =3D *t; release_output_mutex (); @@ -1704,8 +1697,6 @@ fhandler_pty_slave::tcflush (int queue) =20 termios_printf ("tcflush(%d) handle %p", queue, get_handle ()); =20 - reset_switch_to_nat_pipe (); - if (queue =3D=3D TCIFLUSH || queue =3D=3D TCIOFLUSH) { size_t len =3D UINT_MAX; @@ -1725,7 +1716,6 @@ int fhandler_pty_slave::ioctl (unsigned int cmd, void *arg) { termios_printf ("ioctl (%x)", cmd); - reset_switch_to_nat_pipe (); int res =3D fhandler_termios::ioctl (cmd, arg); if (res <=3D 0) return res; @@ -2489,6 +2479,13 @@ fhandler_pty_slave::setup_locale (void) } } =20 +bg_check_types +fhandler_pty_slave::bg_check (int sig, bool dontsignal) +{ + reset_switch_to_nat_pipe (); + return fhandler_termios::bg_check (sig, dontsignal); +} + void fhandler_pty_slave::fixup_after_fork (HANDLE parent) { @@ -2500,7 +2497,6 @@ fhandler_pty_slave::fixup_after_fork (HANDLE parent) void fhandler_pty_slave::fixup_after_exec () { - reset_switch_to_nat_pipe (); create_invisible_console (); =20 if (!close_on_exec ()) @@ -4106,6 +4102,8 @@ fhandler_pty_slave::cleanup_for_non_cygwin_app (handl= e_set_t *p, tty *ttyp, void fhandler_pty_slave::setpgid_aux (pid_t pid) { + reset_switch_to_nat_pipe (); + WaitForSingleObject (pipe_sw_mutex, INFINITE); bool was_nat_fg =3D get_ttyp ()->nat_fg (tc ()->pgid); bool nat_fg =3D get_ttyp ()->nat_fg (pid); diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc index 64e35cf12..4f23dfdef 100644 --- a/winsup/cygwin/select.cc +++ b/winsup/cygwin/select.cc @@ -1353,8 +1353,6 @@ peek_pty_slave (select_record *s, bool from_select) fhandler_base *fh =3D (fhandler_base *) s->fh; fhandler_pty_slave *ptys =3D (fhandler_pty_slave *) fh; =20 - ptys->reset_switch_to_nat_pipe (); - if (s->read_selected) { if (s->read_ready)