public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: sigproc: Do not send signal to myself if exiting.
@ 2021-11-19 11:50 Takashi Yano
  2021-11-19 15:51 ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Yano @ 2021-11-19 11:50 UTC (permalink / raw)
  To: cygwin-patches

- This patch fixes the issue that process sometimes hangs for 60
  seconds with the following scenario.
    1) Open command prompt.
    2) Run "c:\cygwin64\bin\bash -l"
    3) Compipe the following source with mingw compiler.
       /*--- Begin ---*/
       #include <stdio.h>
       int main() {return getchar();}
       /*---- End ----*/
    3) Run "tcsh -c ./a.exe"
    4) Hit Ctrl-C.
---
 winsup/cygwin/sigproc.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 97211edcf..9160dd160 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -603,6 +603,10 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
       its_me = false;
     }
 
+  /* Do not send signal to myself if exiting. */
+  if (its_me && exit_state > ES_EXIT_STARTING && si.si_signo > 0)
+    goto out;
+
   if (its_me)
     sendsig = my_sendsig;
   else
-- 
2.33.0


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

* Re: [PATCH] Cygwin: sigproc: Do not send signal to myself if exiting.
  2021-11-19 11:50 [PATCH] Cygwin: sigproc: Do not send signal to myself if exiting Takashi Yano
@ 2021-11-19 15:51 ` Corinna Vinschen
  2021-11-19 15:53   ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2021-11-19 15:51 UTC (permalink / raw)
  To: cygwin-patches

Hi Takashi,

On Nov 19 20:50, Takashi Yano wrote:
> - This patch fixes the issue that process sometimes hangs for 60
>   seconds with the following scenario.
>     1) Open command prompt.
>     2) Run "c:\cygwin64\bin\bash -l"
>     3) Compipe the following source with mingw compiler.
>        /*--- Begin ---*/
>        #include <stdio.h>
>        int main() {return getchar();}
>        /*---- End ----*/
>     3) Run "tcsh -c ./a.exe"
>     4) Hit Ctrl-C.
> ---
>  winsup/cygwin/sigproc.cc | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
> index 97211edcf..9160dd160 100644
> --- a/winsup/cygwin/sigproc.cc
> +++ b/winsup/cygwin/sigproc.cc
> @@ -603,6 +603,10 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
>        its_me = false;
>      }
>  
> +  /* Do not send signal to myself if exiting. */
> +  if (its_me && exit_state > ES_EXIT_STARTING && si.si_signo > 0)
> +    goto out;
> +
>    if (its_me)
>      sendsig = my_sendsig;
>    else
> -- 
> 2.33.0

Isn't that already handled in wait_sig?  What's the difference here?


Thx,
Corinna

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

* Re: [PATCH] Cygwin: sigproc: Do not send signal to myself if exiting.
  2021-11-19 15:51 ` Corinna Vinschen
@ 2021-11-19 15:53   ` Corinna Vinschen
  2021-11-19 17:14     ` Takashi Yano
  0 siblings, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2021-11-19 15:53 UTC (permalink / raw)
  To: cygwin-patches

On Nov 19 16:51, Corinna Vinschen wrote:
> Hi Takashi,
> 
> On Nov 19 20:50, Takashi Yano wrote:
> > - This patch fixes the issue that process sometimes hangs for 60
> >   seconds with the following scenario.
> >     1) Open command prompt.
> >     2) Run "c:\cygwin64\bin\bash -l"
> >     3) Compipe the following source with mingw compiler.
> >        /*--- Begin ---*/
> >        #include <stdio.h>
> >        int main() {return getchar();}
> >        /*---- End ----*/
> >     3) Run "tcsh -c ./a.exe"
> >     4) Hit Ctrl-C.
> > ---
> >  winsup/cygwin/sigproc.cc | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
> > index 97211edcf..9160dd160 100644
> > --- a/winsup/cygwin/sigproc.cc
> > +++ b/winsup/cygwin/sigproc.cc
> > @@ -603,6 +603,10 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
> >        its_me = false;
> >      }
> >  
> > +  /* Do not send signal to myself if exiting. */
> > +  if (its_me && exit_state > ES_EXIT_STARTING && si.si_signo > 0)
> > +    goto out;
> > +
> >    if (its_me)
> >      sendsig = my_sendsig;
> >    else
> > -- 
> > 2.33.0
> 
> Isn't that already handled in wait_sig?  What's the difference here?

...and where exactly is it waiting 60 secs?

> 
> 
> Thx,
> Corinna

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

* Re: [PATCH] Cygwin: sigproc: Do not send signal to myself if exiting.
  2021-11-19 15:53   ` Corinna Vinschen
@ 2021-11-19 17:14     ` Takashi Yano
  2021-11-19 17:22       ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Yano @ 2021-11-19 17:14 UTC (permalink / raw)
  To: cygwin-patches

On Fri, 19 Nov 2021 16:53:57 +0100
Corinna Vinschen wrote:
> On Nov 19 16:51, Corinna Vinschen wrote:
> > Hi Takashi,
> > 
> > On Nov 19 20:50, Takashi Yano wrote:
> > > - This patch fixes the issue that process sometimes hangs for 60
> > >   seconds with the following scenario.
> > >     1) Open command prompt.
> > >     2) Run "c:\cygwin64\bin\bash -l"
> > >     3) Compipe the following source with mingw compiler.
> > >        /*--- Begin ---*/
> > >        #include <stdio.h>
> > >        int main() {return getchar();}
> > >        /*---- End ----*/
> > >     3) Run "tcsh -c ./a.exe"
> > >     4) Hit Ctrl-C.
> > > ---
> > >  winsup/cygwin/sigproc.cc | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > > 
> > > diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
> > > index 97211edcf..9160dd160 100644
> > > --- a/winsup/cygwin/sigproc.cc
> > > +++ b/winsup/cygwin/sigproc.cc
> > > @@ -603,6 +603,10 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
> > >        its_me = false;
> > >      }
> > >  
> > > +  /* Do not send signal to myself if exiting. */
> > > +  if (its_me && exit_state > ES_EXIT_STARTING && si.si_signo > 0)
> > > +    goto out;
> > > +
> > >    if (its_me)
> > >      sendsig = my_sendsig;
> > >    else
> > > -- 
> > > 2.33.0
> > 
> > Isn't that already handled in wait_sig?  What's the difference here?
> 
> ...and where exactly is it waiting 60 secs?

If sending signal to myself with exit_state > ES_EXIT_STARGING,
wait_for_completion in sig_send() is set to true. Therefore,
sig_send() waits for pack.wakeup event for WSSC (60000 msec) here:

  /* No need to wait for signal completion unless this was a signal to
     this process.

     If it was a signal to this process, wait for a dispatched signal.
     Otherwise just wait for the wait_sig to signal that it has finished
     processing the signal.  */
  if (wait_for_completion)
    {
      sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup);
      rc = WaitForSingleObject (pack.wakeup, WSSC);
      ForceCloseHandle (pack.wakeup);
    }

However, thread wait_sig ignores the signal here:
      /* Don't process signals when we start exiting */
      if (exit_state > ES_EXIT_STARTING && pack.si.si_signo > 0)
        continue;
and does not call SetEvent (pack.wakeup).

As a result, sig_send() hangs for 60 secs.

With this patch, sig_send() does not send signal which will
be ignored in wait_sig().

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

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

* Re: [PATCH] Cygwin: sigproc: Do not send signal to myself if exiting.
  2021-11-19 17:14     ` Takashi Yano
@ 2021-11-19 17:22       ` Corinna Vinschen
  2021-11-19 18:14         ` Takashi Yano
  0 siblings, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2021-11-19 17:22 UTC (permalink / raw)
  To: cygwin-patches

On Nov 20 02:14, Takashi Yano wrote:
> On Fri, 19 Nov 2021 16:53:57 +0100
> Corinna Vinschen wrote:
> > On Nov 19 16:51, Corinna Vinschen wrote:
> > > Isn't that already handled in wait_sig?  What's the difference here?
> > 
> > ...and where exactly is it waiting 60 secs?
> 
> If sending signal to myself with exit_state > ES_EXIT_STARGING,
> wait_for_completion in sig_send() is set to true. Therefore,
> sig_send() waits for pack.wakeup event for WSSC (60000 msec) here:
> 
>   /* No need to wait for signal completion unless this was a signal to
>      this process.
> 
>      If it was a signal to this process, wait for a dispatched signal.
>      Otherwise just wait for the wait_sig to signal that it has finished
>      processing the signal.  */
>   if (wait_for_completion)
>     {
>       sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup);
>       rc = WaitForSingleObject (pack.wakeup, WSSC);
>       ForceCloseHandle (pack.wakeup);
>     }
> 
> However, thread wait_sig ignores the signal here:
>       /* Don't process signals when we start exiting */
>       if (exit_state > ES_EXIT_STARTING && pack.si.si_signo > 0)
>         continue;
> and does not call SetEvent (pack.wakeup).
> 
> As a result, sig_send() hangs for 60 secs.
> 
> With this patch, sig_send() does not send signal which will
> be ignored in wait_sig().

Ah, ok, that makes sense.  Thanks for the explanation.  Please push.


Thanks,
Corinna

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

* Re: [PATCH] Cygwin: sigproc: Do not send signal to myself if exiting.
  2021-11-19 17:22       ` Corinna Vinschen
@ 2021-11-19 18:14         ` Takashi Yano
  0 siblings, 0 replies; 6+ messages in thread
From: Takashi Yano @ 2021-11-19 18:14 UTC (permalink / raw)
  To: cygwin-patches

On Fri, 19 Nov 2021 18:22:40 +0100
Corinna Vinschen wrote:
> On Nov 20 02:14, Takashi Yano wrote:
> > On Fri, 19 Nov 2021 16:53:57 +0100
> > Corinna Vinschen wrote:
> > > On Nov 19 16:51, Corinna Vinschen wrote:
> > > > Isn't that already handled in wait_sig?  What's the difference here?
> > > 
> > > ...and where exactly is it waiting 60 secs?
> > 
> > If sending signal to myself with exit_state > ES_EXIT_STARGING,
> > wait_for_completion in sig_send() is set to true. Therefore,
> > sig_send() waits for pack.wakeup event for WSSC (60000 msec) here:
> > 
> >   /* No need to wait for signal completion unless this was a signal to
> >      this process.
> > 
> >      If it was a signal to this process, wait for a dispatched signal.
> >      Otherwise just wait for the wait_sig to signal that it has finished
> >      processing the signal.  */
> >   if (wait_for_completion)
> >     {
> >       sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup);
> >       rc = WaitForSingleObject (pack.wakeup, WSSC);
> >       ForceCloseHandle (pack.wakeup);
> >     }
> > 
> > However, thread wait_sig ignores the signal here:
> >       /* Don't process signals when we start exiting */
> >       if (exit_state > ES_EXIT_STARTING && pack.si.si_signo > 0)
> >         continue;
> > and does not call SetEvent (pack.wakeup).
> > 
> > As a result, sig_send() hangs for 60 secs.
> > 
> > With this patch, sig_send() does not send signal which will
> > be ignored in wait_sig().
> 
> Ah, ok, that makes sense.  Thanks for the explanation.  Please push.

Ah, this patch may cause race issue regarding exit_state.
I will submit another patch which overrides this patch.

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

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

end of thread, other threads:[~2021-11-19 18:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-19 11:50 [PATCH] Cygwin: sigproc: Do not send signal to myself if exiting Takashi Yano
2021-11-19 15:51 ` Corinna Vinschen
2021-11-19 15:53   ` Corinna Vinschen
2021-11-19 17:14     ` Takashi Yano
2021-11-19 17:22       ` Corinna Vinschen
2021-11-19 18:14         ` Takashi Yano

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