public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH v2] Cygwin: console: Abort read() on signal if SA_RESTART is not set.
@ 2021-02-14  9:42 Takashi Yano
  2021-02-15 12:04 ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Takashi Yano @ 2021-02-14  9:42 UTC (permalink / raw)
  To: cygwin-patches

- Currently, console read() keeps reading after SIGWINCH is sent
  even if SA_RESTART flag is not set. With this patch, read()
  returns EINTR on SIGWINCH if SA_RESTART flag is not set.
  The same problem for SIGQUIT and SIGTSTP has also been fixed.
---
 winsup/cygwin/fhandler_console.cc | 7 +++----
 winsup/cygwin/fhandler_termios.cc | 1 +
 winsup/cygwin/tty.cc              | 1 +
 winsup/cygwin/tty.h               | 1 +
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 3c0783575..78af6cf2b 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -586,12 +586,11 @@ wait_retry:
 	case input_ok: /* input ready */
 	  break;
 	case input_signalled: /* signalled */
-	  release_input_mutex ();
-	  /* The signal will be handled by cygwait() above. */
-	  continue;
 	case input_winch:
 	  release_input_mutex ();
-	  continue;
+	  if (global_sigs[get_ttyp ()->last_sig].sa_flags & SA_RESTART)
+	    continue;
+	  goto sig_exit;
 	default:
 	  /* Should not come here */
 	  release_input_mutex ();
diff --git a/winsup/cygwin/fhandler_termios.cc b/winsup/cygwin/fhandler_termios.cc
index 9fbace95c..e8daf946b 100644
--- a/winsup/cygwin/fhandler_termios.cc
+++ b/winsup/cygwin/fhandler_termios.cc
@@ -133,6 +133,7 @@ tty_min::kill_pgrp (int sig)
   siginfo_t si = {0};
   si.si_signo = sig;
   si.si_code = SI_KERNEL;
+  last_sig = sig;
 
   for (unsigned i = 0; i < pids.npids; i++)
     {
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index 41f81f694..7627cd6c7 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -251,6 +251,7 @@ tty::init ()
   master_is_running_as_service = false;
   req_xfer_input = false;
   pcon_input_state = to_cyg;
+  last_sig = 0;
 }
 
 HANDLE
diff --git a/winsup/cygwin/tty.h b/winsup/cygwin/tty.h
index e1de7ab46..a8ddd68d6 100644
--- a/winsup/cygwin/tty.h
+++ b/winsup/cygwin/tty.h
@@ -48,6 +48,7 @@ public:
   fh_devices ntty;
   ULONGLONG last_ctrl_c;	/* tick count of last ctrl-c */
   bool is_console;
+  int last_sig;
 
   IMPLEMENT_STATUS_FLAG (bool, initialized)
   IMPLEMENT_STATUS_FLAG (bool, rstcons)
-- 
2.30.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] Cygwin: console: Abort read() on signal if SA_RESTART is not set.
  2021-02-14  9:42 [PATCH v2] Cygwin: console: Abort read() on signal if SA_RESTART is not set Takashi Yano
@ 2021-02-15 12:04 ` Corinna Vinschen
  2021-02-15 13:08   ` Takashi Yano
  0 siblings, 1 reply; 4+ messages in thread
From: Corinna Vinschen @ 2021-02-15 12:04 UTC (permalink / raw)
  To: cygwin-patches

Hi Takashi,

On Feb 14 18:42, Takashi Yano via Cygwin-patches wrote:
> - Currently, console read() keeps reading after SIGWINCH is sent
>   even if SA_RESTART flag is not set. With this patch, read()
>   returns EINTR on SIGWINCH if SA_RESTART flag is not set.
>   The same problem for SIGQUIT and SIGTSTP has also been fixed.
> ---
>  winsup/cygwin/fhandler_console.cc | 7 +++----
>  winsup/cygwin/fhandler_termios.cc | 1 +
>  winsup/cygwin/tty.cc              | 1 +
>  winsup/cygwin/tty.h               | 1 +
>  4 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
> index 3c0783575..78af6cf2b 100644
> --- a/winsup/cygwin/fhandler_console.cc
> +++ b/winsup/cygwin/fhandler_console.cc
> @@ -586,12 +586,11 @@ wait_retry:
>  	case input_ok: /* input ready */
>  	  break;
>  	case input_signalled: /* signalled */
> -	  release_input_mutex ();
> -	  /* The signal will be handled by cygwait() above. */
> -	  continue;
>  	case input_winch:
>  	  release_input_mutex ();
> -	  continue;
> +	  if (global_sigs[get_ttyp ()->last_sig].sa_flags & SA_RESTART)

Shouldn't this check for last_sig != 0 first?


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] Cygwin: console: Abort read() on signal if SA_RESTART is not set.
  2021-02-15 12:04 ` Corinna Vinschen
@ 2021-02-15 13:08   ` Takashi Yano
  2021-02-15 13:23     ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Takashi Yano @ 2021-02-15 13:08 UTC (permalink / raw)
  To: cygwin-patches

On Mon, 15 Feb 2021 13:04:41 +0100
Corinna Vinschen wrote:
> On Feb 14 18:42, Takashi Yano via Cygwin-patches wrote:
> > - Currently, console read() keeps reading after SIGWINCH is sent
> >   even if SA_RESTART flag is not set. With this patch, read()
> >   returns EINTR on SIGWINCH if SA_RESTART flag is not set.
> >   The same problem for SIGQUIT and SIGTSTP has also been fixed.
> > ---
> >  winsup/cygwin/fhandler_console.cc | 7 +++----
> >  winsup/cygwin/fhandler_termios.cc | 1 +
> >  winsup/cygwin/tty.cc              | 1 +
> >  winsup/cygwin/tty.h               | 1 +
> >  4 files changed, 6 insertions(+), 4 deletions(-)
> > 
> > diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
> > index 3c0783575..78af6cf2b 100644
> > --- a/winsup/cygwin/fhandler_console.cc
> > +++ b/winsup/cygwin/fhandler_console.cc
> > @@ -586,12 +586,11 @@ wait_retry:
> >  	case input_ok: /* input ready */
> >  	  break;
> >  	case input_signalled: /* signalled */
> > -	  release_input_mutex ();
> > -	  /* The signal will be handled by cygwait() above. */
> > -	  continue;
> >  	case input_winch:
> >  	  release_input_mutex ();
> > -	  continue;
> > +	  if (global_sigs[get_ttyp ()->last_sig].sa_flags & SA_RESTART)
> 
> Shouldn't this check for last_sig != 0 first?

This code is reached only after SIGINT, SIGTSTP, SIGQUIT (case
input_signalled) or SIGWINCH (case input_winch) has been sent.
Therefore, last_sig should be one of them here.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] Cygwin: console: Abort read() on signal if SA_RESTART is not set.
  2021-02-15 13:08   ` Takashi Yano
@ 2021-02-15 13:23     ` Corinna Vinschen
  0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2021-02-15 13:23 UTC (permalink / raw)
  To: cygwin-patches

On Feb 15 22:08, Takashi Yano via Cygwin-patches wrote:
> On Mon, 15 Feb 2021 13:04:41 +0100
> Corinna Vinschen wrote:
> > On Feb 14 18:42, Takashi Yano via Cygwin-patches wrote:
> > > - Currently, console read() keeps reading after SIGWINCH is sent
> > >   even if SA_RESTART flag is not set. With this patch, read()
> > >   returns EINTR on SIGWINCH if SA_RESTART flag is not set.
> > >   The same problem for SIGQUIT and SIGTSTP has also been fixed.
> > > ---
> > >  winsup/cygwin/fhandler_console.cc | 7 +++----
> > >  winsup/cygwin/fhandler_termios.cc | 1 +
> > >  winsup/cygwin/tty.cc              | 1 +
> > >  winsup/cygwin/tty.h               | 1 +
> > >  4 files changed, 6 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
> > > index 3c0783575..78af6cf2b 100644
> > > --- a/winsup/cygwin/fhandler_console.cc
> > > +++ b/winsup/cygwin/fhandler_console.cc
> > > @@ -586,12 +586,11 @@ wait_retry:
> > >  	case input_ok: /* input ready */
> > >  	  break;
> > >  	case input_signalled: /* signalled */
> > > -	  release_input_mutex ();
> > > -	  /* The signal will be handled by cygwait() above. */
> > > -	  continue;
> > >  	case input_winch:
> > >  	  release_input_mutex ();
> > > -	  continue;
> > > +	  if (global_sigs[get_ttyp ()->last_sig].sa_flags & SA_RESTART)
> > 
> > Shouldn't this check for last_sig != 0 first?
> 
> This code is reached only after SIGINT, SIGTSTP, SIGQUIT (case
> input_signalled) or SIGWINCH (case input_winch) has been sent.
> Therefore, last_sig should be one of them here.

Thanks, pushed.


Corinna

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-15 13:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-14  9:42 [PATCH v2] Cygwin: console: Abort read() on signal if SA_RESTART is not set Takashi Yano
2021-02-15 12:04 ` Corinna Vinschen
2021-02-15 13:08   ` Takashi Yano
2021-02-15 13:23     ` Corinna Vinschen

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).