From 61e06f3b12afe464c3b4fcd23d4a3a07251c50ac Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 3 Sep 2022 10:22:33 +0000 Subject: Include mitigation for BSD disease in sigaction wrapper Signed-off-by: Laurent Bercot --- src/libstddjb/sig_catch.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libstddjb/sig_catch.c b/src/libstddjb/sig_catch.c index 5195d4b..a11e317 100644 --- a/src/libstddjb/sig_catch.c +++ b/src/libstddjb/sig_catch.c @@ -2,14 +2,28 @@ /* MT-unsafe */ +#include +#include + #include +#include #include #include +#include + + /* + BSD fails sigaction() with EINVAL on non-catchable signals, whereas + every reasonable OS succeeds and simply ignores the signal handler. + */ int sig_catch (int sig, sig_func_ref f) { struct sigaction action = { .sa_handler = f, .sa_flags = SA_RESTART | SA_NOCLDSTOP } ; sigfillset(&action.sa_mask) ; - return sigaction(sig, &action, 0) >= 0 ; + return sigaction(sig, &action, 0) >= 0 +#ifdef SKALIBS_BSD_SUCKS + || (errno == EINVAL && sig >= 1 && sig <= NSIG) +#endif + ; } -- cgit v1.2.3