diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2021-08-29 11:14:14 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-08-29 11:15:32 -0700 |
commit | 078321ebeb4d9e83e900278154dbf47ec2758295 (patch) | |
tree | 24f633148b7eb89922f02922e5ef9ee2dbe0d370 | |
parent | 9b20182d48481c7ca647ff8926feeb8e1da4f7b0 (diff) | |
download | diffutils-078321ebeb4d9e83e900278154dbf47ec2758295.tar.gz |
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.
-rw-r--r-- | src/util.c | 36 |
1 files changed, 15 insertions, 21 deletions
@@ -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 } |