diff options
Diffstat (limited to 'src/libstddjb/selfpipe_trapset.c')
-rw-r--r-- | src/libstddjb/selfpipe_trapset.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/libstddjb/selfpipe_trapset.c b/src/libstddjb/selfpipe_trapset.c index 542ad10..9559c07 100644 --- a/src/libstddjb/selfpipe_trapset.c +++ b/src/libstddjb/selfpipe_trapset.c @@ -7,60 +7,66 @@ #include <errno.h> #include <signal.h> #include <sys/signalfd.h> + #include <skalibs/selfpipe.h> #include "selfpipe-internal.h" int selfpipe_trapset (sigset_t const *set) { sigset_t old ; - if (selfpipe_fd < 0) return (errno = EBADF, -1) ; - if (sigprocmask(SIG_BLOCK, set, &old) < 0) return -1 ; + if (selfpipe_fd < 0) return (errno = EBADF, 0) ; + if (sigprocmask(SIG_SETMASK, set, &old) < 0) return 0 ; if (signalfd(selfpipe_fd, set, SFD_NONBLOCK | SFD_CLOEXEC) < 0) { int e = errno ; sigprocmask(SIG_SETMASK, &old, 0) ; errno = e ; - return -1 ; + return 0 ; } selfpipe_caught = *set ; - return 0 ; + return 1 ; } #else #include <skalibs/nonposix.h> +#include <skalibs/bsdsnowflake.h> + #include <errno.h> #include <signal.h> -#include <skalibs/sig.h> + #include <skalibs/nsig.h> +#include <skalibs/sig.h> #include <skalibs/selfpipe.h> #include "selfpipe-internal.h" int selfpipe_trapset (sigset_t const *set) { unsigned int i = 1 ; - if (selfpipe_fd < 0) return (errno = EBADF, -1) ; + if (selfpipe_fd < 0) return (errno = EBADF, 0) ; for (; i < SKALIBS_NSIG ; i++) { int h = sigismember(set, i) ; if (h < 0) continue ; if (h) { - if (sig_catcha(i, &selfpipe_ssa) < 0) break ; + if (!sig_catch(i, &selfpipe_tophalf)) goto err ; } else if (sigismember(&selfpipe_caught, i)) { - if (sig_restore(i) < 0) break ; + if (!sig_restore(i)) goto err ; } } - if (i < SKALIBS_NSIG || sigprocmask(SIG_UNBLOCK, set, 0) < 0) + sig_blocknone() ; + selfpipe_caught = *set ; + return 1 ; + + err: { int e = errno ; sig_restoreto(set, i) ; errno = e ; - return -1 ; } - selfpipe_caught = *set ; return 0 ; } |