>From 078321ebeb4d9e83e900278154dbf47ec2758295 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 29 Aug 2021 11:14:14 -0700 Subject: [PATCH] diff: port better to MS-Windows Problem reported by Gisle Vanem (Bug#36488#30). * src/util.c (xsigaction) [SA_NOCLDSTOP]: Remove; no longer needed. (install_signal_handlers): If the first call to sigaction or signal fails, do not exit; just skip the signal and continue, in case the runtime does not support the signal even though the corresponding SIG* macro is defined. --- src/util.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/src/util.c b/src/util.c index 8e676c8..f8b911a 100644 --- a/src/util.c +++ b/src/util.c @@ -159,16 +159,7 @@ print_message_queue (void) } } - -#if SA_NOCLDSTOP -static void -xsigaction (int sig, struct sigaction const *restrict act, - struct sigaction *restrict oact) -{ - if (sigaction (sig, act, oact) != 0) - pfatal_with_name ("sigaction"); -} -#endif +/* Signal handling, needed for restoring default colors. */ static void xsigaddset (sigset_t *set, int sig) @@ -321,8 +312,7 @@ install_signal_handlers (void) for (int j = 0; j < nsigs; j++) { struct sigaction actj; - xsigaction (sig[j], NULL, &actj); - if (actj.sa_handler != SIG_IGN) + if (sigaction (sig[j], NULL, &actj) == 0 && actj.sa_handler != SIG_IGN) xsigaddset (&caught_signals, sig[j]); } @@ -334,19 +324,23 @@ install_signal_handlers (void) if (xsigismember (&caught_signals, sig[j])) { act.sa_handler = sig[j] == SIGTSTP ? stophandler : sighandler; - xsigaction (sig[j], &act, NULL); + if (sigaction (sig[j], &act, NULL) != 0) + pfatal_with_name ("sigaction"); some_signals_caught = true; } #else for (int j = 0; j < nsigs; j++) - if (xsignal (sig[j], SIG_IGN) != SIG_IGN) - { - xsigaddset (&caught_signals, sig[j]); - xsignal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler); - some_signals_caught = true; - if (siginterrupt (sig[j], 0) != 0) - pfatal_with_name ("siginterrupt"); - } + { + signal_handler h = signal (sig[j], SIG_IGN); + if (h != SIG_IGN && h != SIG_ERR) + { + xsigaddset (&caught_signals, sig[j]); + xsignal (sig[j], sig[j] == SIGTSTP ? stophandler : sighandler); + some_signals_caught = true; + if (siginterrupt (sig[j], 0) != 0) + pfatal_with_name ("siginterrupt"); + } + } #endif } -- 2.30.2