skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 61e06f3b12afe464c3b4fcd23d4a3a07251c50ac
parent 2abc3b2c555d3dd6f9707b4e866d7984ad9048d6
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Sat,  3 Sep 2022 10:22:33 +0000

 Include mitigation for BSD disease in sigaction wrapper

Signed-off-by: Laurent Bercot <ska@appnovation.com>

Diffstat:
Msrc/libstddjb/sig_catch.c | 16+++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/libstddjb/sig_catch.c b/src/libstddjb/sig_catch.c @@ -2,14 +2,28 @@ /* MT-unsafe */ +#include <skalibs/nonposix.h> +#include <skalibs/bsdsnowflake.h> + #include <signal.h> +#include <errno.h> #include <skalibs/functypes.h> #include <skalibs/sig.h> +#include <skalibs/nsig.h> + + /* + 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 + ; }