diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libstddjb/sig_catch.c | 16 |
1 files changed, 15 insertions, 1 deletions
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 <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 + ; } |