Pádraig Brady <[email protected]> writes:
> #if ! SA_NOCLDSTOP
> - static bool caught_sig[nsigs];
> + static bool caught_sig[nsigs + nstop];
> #endif
>
> if (init)
> @@ -1633,29 +1617,34 @@ signal_setup (bool init)
> struct sigaction act;
>
> sigemptyset (&caught_signals);
> - for (int j = 0; j < nsigs; j++)
> + for (int j = 0; j < nsigs + nstop; j++)
> {
> - sigaction (sig[j], nullptr, &act);
> + int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs];
> + sigaction (sig, nullptr, &act);
> if (act.sa_handler != SIG_IGN)
> - sigaddset (&caught_signals, sig[j]);
> + sigaddset (&caught_signals, sig);
> }
>
> act.sa_mask = caught_signals;
> act.sa_flags = SA_RESTART;
>
> - for (int j = 0; j < nsigs; j++)
> - if (sigismember (&caught_signals, sig[j]))
> - {
> - act.sa_handler = sig[j] == SIGTSTP ? stophandler : sighandler;
> - sigaction (sig[j], &act, nullptr);
> - }
> + for (int j = 0; j < nsigs + nstop; j++)
> + {
> + int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs];
> + if (sigismember (&caught_signals, sig))
> + {
> + act.sa_handler = j < nsigs ? sighandler : stophandler;
> + sigaction (sig, &act, nullptr);
> + }
> + }
> #else
> - for (int j = 0; j < nsigs; j++)
> + for (int j = 0; j < nsigs + nstop; j++)
> {
> - caught_sig[j] = (signal (sig[j], SIG_IGN) != SIG_IGN);
> + int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs];
> + caught_sig[j] = (signal (sig, SIG_IGN) != SIG_IGN);
> if (caught_sig[j])
> {
> - signal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler);
> + signal (sig, j < nsigs ? sighandler : stophandler);
> siginterrupt (sig[j], 0);
> }
> }
> @@ -1663,15 +1652,16 @@ signal_setup (bool init)
> }
> else /* restore. */
> {
> + for (int j = 0; j < nsigs + nstop; j++)
> + {
> + int sig = j < nsigs ? term_sig[j]: stop_sig[j - nsigs];
> #if SA_NOCLDSTOP
> - for (int j = 0; j < nsigs; j++)
> - if (sigismember (&caught_signals, sig[j]))
> - signal (sig[j], SIG_DFL);
> + if (sigismember (&caught_signals, sig))
> #else
> - for (int j = 0; j < nsigs; j++)
> - if (caught_sig[j])
> - signal (sig[j], SIG_DFL);
> + if (caught_sig[j])
> #endif
> + signal (sig, SIG_DFL);
> + }
> }
> }
I wonder if we can remove the fallback for platforms without
sigaction. Gnulib doesn't document it missing for any platforms other
than Windows, which it has a implementation for [1]. WDYT?
> +static int const term_sig[] =
> + {
> + SIGALRM, /* our timeout. */
> + SIGINT, /* Ctrl-C at terminal for example. */
> + SIGQUIT, /* Ctrl-\ at terminal for example. */
> + SIGHUP, /* terminal closed for example. */
> + SIGTERM, /* if terminated, stop monitored proc. */
> +
> + SIGPIPE, SIGUSR1, SIGUSR2,
> +
> + SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, SIGSEGV,
> +
> +# ifdef SIGXCPU
> + SIGXCPU,
> +# endif
> +# ifdef SIGXFSZ
> + SIGXFSZ,
> +# endif
> +# ifdef SIGSYS
> + SIGSYS,
> +# endif
> +# ifdef SIGVTALRM
> + SIGVTALRM,
> +# endif
> +# ifdef SIGPROF
> + SIGPROF,
> +# endif
> +# ifdef SIGPOLL
> + SIGPOLL,
> +# endif
> +# ifdef SIGPWR
> + SIGPWR,
> +# endif
> +# ifdef SIGSTKFLT
> + SIGSTKFLT,
> +# endif
> + };
Should we #ifdef any of the signals not specified by ISO C? That is
SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, and SIGTERM.
The patch is a nice cleanup though, thanks.
Collin
[1] https://www.gnu.org/software/gnulib/manual/html_node/sigaction.html