summaryrefslogtreecommitdiff
path: root/src/libstddjb
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2022-09-03 10:22:33 +0000
committerLaurent Bercot <ska@appnovation.com>2022-09-03 10:22:33 +0000
commit61e06f3b12afe464c3b4fcd23d4a3a07251c50ac (patch)
tree366c2cf13b62284f394180744a9b617411f9ea9f /src/libstddjb
parent2abc3b2c555d3dd6f9707b4e866d7984ad9048d6 (diff)
downloadskalibs-61e06f3b12afe464c3b4fcd23d4a3a07251c50ac.tar.xz
Include mitigation for BSD disease in sigaction wrapper
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libstddjb')
-rw-r--r--src/libstddjb/sig_catch.c16
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
+ ;
}