sig_catch.c (546B)
1 /* ISC license. */ 2 3 /* MT-unsafe */ 4 5 #include <skalibs/nonposix.h> 6 7 #include <signal.h> 8 #include <errno.h> 9 10 #include <skalibs/functypes.h> 11 #include <skalibs/sig.h> 12 #include <skalibs/nsig.h> 13 14 /* 15 We don't want to fail on non-catchable signals, 16 even if sigaction() does. 17 */ 18 19 int sig_catch (int sig, sig_func_ref f) 20 { 21 struct sigaction action = { .sa_handler = f, .sa_flags = SA_RESTART | SA_NOCLDSTOP } ; 22 sigfillset(&action.sa_mask) ; 23 return sigaction(sig, &action, 0) >= 0 24 || (errno == EINVAL && sig >= 1 && sig < SKALIBS_NSIG) ; 25 }