From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 8231638582A1; Thu, 28 Jul 2022 15:17:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8231638582A1 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-3_3-branch] Cygwin: console: Add missing input_mutex guard. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_3-branch X-Git-Oldrev: df0890575ce1aa9dfa643a42899a1904c88799c5 X-Git-Newrev: 0853f89176eb66f50b015adfa6530983d3aa38ee Message-Id: <20220728151723.8231638582A1@sourceware.org> Date: Thu, 28 Jul 2022 15:17: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: Thu, 28 Jul 2022 15:17:23 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D0853f89176e= b66f50b015adfa6530983d3aa38ee commit 0853f89176eb66f50b015adfa6530983d3aa38ee Author: Takashi Yano Date: Thu Jul 28 21:52:39 2022 +0900 Cygwin: console: Add missing input_mutex guard. =20 - Setting con.disable_master_thread flag should be guarded by input_mutex, however, it was not. This patch fixes that. Diff: --- winsup/cygwin/fhandler.h | 1 + winsup/cygwin/fhandler_console.cc | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 2b403d06e..e47b38e9a 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -2294,6 +2294,7 @@ private: static void cleanup_for_non_cygwin_app (handle_set_t *p); static void set_console_mode_to_native (); bool need_console_handler (); + static void set_disable_master_thread (bool x); =20 friend tty_min * tty_list::get_cttyp (); }; diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_con= sole.cc index e080fd6c8..e90b8d5ee 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -790,7 +790,7 @@ fhandler_console::setup_for_non_cygwin_app () (get_ttyp ()->getpgid ()=3D=3D myself->pgid) ? tty::native : tty::rest= ore; set_input_mode (conmode, &tc ()->ti, get_handle_set ()); set_output_mode (conmode, &tc ()->ti, get_handle_set ()); - con.disable_master_thread =3D true; + set_disable_master_thread (true); } =20 void @@ -806,7 +806,7 @@ fhandler_console::cleanup_for_non_cygwin_app (handle_se= t_t *p) (con.owner =3D=3D myself->pid) ? tty::restore : tty::cygwin; set_output_mode (conmode, ti, p); set_input_mode (conmode, ti, p); - con.disable_master_thread =3D (con.owner =3D=3D myself->pid); + set_disable_master_thread (con.owner =3D=3D myself->pid); } =20 /* Return the tty structure associated with a given tty number. If the @@ -984,7 +984,7 @@ fhandler_console::bg_check (int sig, bool dontsignal) if (sig =3D=3D SIGTTIN) { set_input_mode (tty::cygwin, &tc ()->ti, get_handle_set ()); - con.disable_master_thread =3D false; + set_disable_master_thread (false); } if (sig =3D=3D SIGTTOU) set_output_mode (tty::cygwin, &tc ()->ti, get_handle_set ()); @@ -1715,7 +1715,7 @@ fhandler_console::post_open_setup (int fd) if (fd =3D=3D 0) { set_input_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set); - con.disable_master_thread =3D false; + set_disable_master_thread (false); } else if (fd =3D=3D 1 || fd =3D=3D 2) set_output_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set); @@ -1743,7 +1743,7 @@ fhandler_console::close () /* Cleaning-up console mode for cygwin apps. */ set_output_mode (tty::restore, &get_ttyp ()->ti, &handle_set); set_input_mode (tty::restore, &get_ttyp ()->ti, &handle_set); - con.disable_master_thread =3D true; + set_disable_master_thread (true); } } =20 @@ -3969,7 +3969,7 @@ fhandler_console::set_console_mode_to_native () termios *cons_ti =3D &cons->tc ()->ti; set_input_mode (tty::native, cons_ti, cons->get_handle_set ()); set_output_mode (tty::native, cons_ti, cons->get_handle_set ()); - con.disable_master_thread =3D true; + set_disable_master_thread (true); break; } } @@ -4322,3 +4322,14 @@ fhandler_console::need_console_handler () { return con.disable_master_thread || con.master_thread_suspended; } + +void +fhandler_console::set_disable_master_thread (bool x) +{ + if (cygheap->ctty->get_major () !=3D DEV_CONS_MAJOR) + return; + fhandler_console *cons =3D (fhandler_console *) cygheap->ctty; + cons->acquire_input_mutex (mutex_timeout); + con.disable_master_thread =3D x; + cons->release_input_mutex (); +}