diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2021-08-30 10:29:16 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-08-30 10:32:18 -0700 |
commit | e1458a3137ee9d5208fb5b2fd71a77f69ead21ca (patch) | |
tree | 320ad51b9b74358f964838d8602546a8653a4c43 | |
parent | f1de694cbffac2acc392e3db6a038b17f3b77d02 (diff) | |
download | diffutils-e1458a3137ee9d5208fb5b2fd71a77f69ead21ca.tar.gz |
maint: port better to non-POSIX
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.
-rw-r--r-- | src/util.c | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -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"); |