From e1458a3137ee9d5208fb5b2fd71a77f69ead21ca Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 30 Aug 2021 10:29:16 -0700 Subject: maint: port better to non-POSIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem privately reported by Gisle Vanem for MS-Windows. * src/util.c (sig, install_signal_handlers): Don’t assume SIGTSTP, SIGALRM, SIGQUIT. (is_tstp_index): New function, for use in SIGTSTP avoidance. --- src/util.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/util.c b/src/util.c index 7e77522..a3d2ab4 100644 --- a/src/util.c +++ b/src/util.c @@ -299,11 +299,20 @@ process_signals (void) and which of them are actually caught. */ static int const sig[] = { - /* This one is handled specially. */ +#ifdef SIGTSTP + /* This one is handled specially; see is_tstp_index. */ SIGTSTP, +#endif /* The usual suspects. */ - SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGQUIT, SIGTERM, +#ifdef SIGALRM + SIGALRM, +#endif + SIGHUP, SIGINT, SIGPIPE, +#ifdef SIGQUIT + SIGQUIT, +#endif + SIGTERM, #ifdef SIGPOLL SIGPOLL, #endif @@ -322,6 +331,17 @@ static int const sig[] = }; enum { nsigs = sizeof (sig) / sizeof *(sig) }; +/* True if sig[j] == SIGTSTP. */ +static bool +is_tstp_index (int j) +{ +#ifdef SIGTSTP + return j == 0; +#else + return false; +#endif +} + static void install_signal_handlers (void) { @@ -343,7 +363,7 @@ install_signal_handlers (void) for (int j = 0; j < nsigs; j++) if (xsigismember (&caught_signals, sig[j])) { - act.sa_handler = sig[j] == SIGTSTP ? stophandler : sighandler; + act.sa_handler = is_tstp_index (j) ? stophandler : sighandler; if (sigaction (sig[j], &act, NULL) != 0) pfatal_with_name ("sigaction"); some_signals_caught = true; @@ -355,7 +375,7 @@ install_signal_handlers (void) if (h != SIG_IGN && h != SIG_ERR) { xsigaddset (&caught_signals, sig[j]); - xsignal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler); + xsignal (sig[j], is_tstp_index (j) ? stophandler : sighandler); some_signals_caught = true; if (siginterrupt (sig[j], 0) != 0) pfatal_with_name ("siginterrupt"); -- cgit v1.2.1