Skip to content

Commit

Permalink
Cygwin: signal: Do not handle signal when __SIGFLUSHFAST is sent
Browse files Browse the repository at this point in the history
The commit a22a0ad was not exactly the correct thing. Even with
the patch, some hangs still happen. This patch overrides the previous
commit togerther with the patch making cygwait() reentrant to fix these
hangs.

Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256954.html
Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256987.html
Fixes: d243e51 ("Cygwin: signal: Fix deadlock between main thread and sig thread")
Fixes: a22a0ad ("Cygwin: signal: Do not handle signal when __SIGFLUSHFAST is sent")
Reported-by: Daisuke Fujimura <[email protected]>
Reported-by: Jeremy Drake <[email protected]>
Reviewed-by:
Signed-off-by: Takashi Yano <[email protected]>
  • Loading branch information
tyan0 authored and jeremyd2019 committed Jan 20, 2025
1 parent 96aae8a commit b6a94e2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions winsup/cygwin/sigproc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,12 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
memcpy (p, si._si_commune._si_str, n); p += n;
}

unsigned cw_mask;
if (pack.si.si_signo == __SIGFLUSHFAST)
cw_mask = 0;
else
cw_mask = cw_sig_restart;

DWORD nb;
BOOL res;
/* Try multiple times to send if packsize != nb since that probably
Expand All @@ -751,8 +757,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
res = WriteFile (sendsig, leader, packsize, &nb, NULL);
if (!res || packsize == nb)
break;
if (cygwait (NULL, 10, cw_sig_eintr) == WAIT_SIGNALED)
_my_tls.call_signal_handler ();
cygwait (NULL, 10, cw_mask);
res = 0;
}

Expand Down Expand Up @@ -785,7 +790,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
if (wait_for_completion)
{
sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup);
rc = cygwait (pack.wakeup, WSSC);
rc = cygwait (pack.wakeup, WSSC, cw_mask);
ForceCloseHandle (pack.wakeup);
}
else
Expand All @@ -806,9 +811,6 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
rc = -1;
}

if (wait_for_completion && si.si_signo != __SIGFLUSHFAST)
_my_tls.call_signal_handler ();

out:
if (communing && rc)
{
Expand Down

0 comments on commit b6a94e2

Please sign in to comment.