diff options
Diffstat (limited to 'libc/signal/sigset.c')
-rw-r--r-- | libc/signal/sigset.c | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/libc/signal/sigset.c b/libc/signal/sigset.c index f4c04dc3e..03f3dc869 100644 --- a/libc/signal/sigset.c +++ b/libc/signal/sigset.c @@ -31,51 +31,39 @@ __sighandler_t sigset (int sig, __sighandler_t disp) struct sigaction act, oact; sigset_t set; + /* Check signal extents to protect __sigismember. */ + if (disp == SIG_ERR || sig < 1 || sig >= NSIG) + { + __set_errno (EINVAL); + return SIG_ERR; + } + #ifdef SIG_HOLD /* Handle SIG_HOLD first. */ if (disp == SIG_HOLD) { - /* Create an empty signal set. */ - if (__sigemptyset (&set) < 0) - return SIG_ERR; - - /* Add the specified signal. */ - if (__sigaddset (&set, sig) < 0) - return SIG_ERR; + __sigemptyset (&set); + __sigaddset (&set, sig); /* Add the signal set to the current signal mask. */ - if (sigprocmask (SIG_BLOCK, &set, NULL) < 0) - return SIG_ERR; + sigprocmask (SIG_BLOCK, &set, NULL); /* can't fail */ return SIG_HOLD; } #endif /* SIG_HOLD */ - /* Check signal extents to protect __sigismember. */ - if (disp == SIG_ERR || sig < 1 || sig >= NSIG) - { - __set_errno (EINVAL); - return SIG_ERR; - } - + memset(&act, 0, sizeof(act)); act.sa_handler = disp; - if (__sigemptyset (&act.sa_mask) < 0) - return SIG_ERR; - act.sa_flags = 0; + /* In Linux (as of 2.6.25), fails only if sig is SIGKILL or SIGSTOP */ if (sigaction (sig, &act, &oact) < 0) return SIG_ERR; - /* Create an empty signal set. */ - if (__sigemptyset (&set) < 0) - return SIG_ERR; - - /* Add the specified signal. */ - if (__sigaddset (&set, sig) < 0) - return SIG_ERR; + /* Create an empty signal set. Add the specified signal. */ + __sigemptyset (&set); + __sigaddset (&set, sig); /* Remove the signal set from the current signal mask. */ - if (sigprocmask (SIG_UNBLOCK, &set, NULL) < 0) - return SIG_ERR; + sigprocmask (SIG_UNBLOCK, &set, NULL); /* can't fail */ return oact.sa_handler; } |