22
22
#include <signal.h>
23
23
#include <string.h> /* For the real memset prototype. */
25
libc_hidden_proto(sigaction)
26
libc_hidden_proto(sigprocmask)
28
26
/* Set the disposition for SIG. */
29
27
__sighandler_t sigset (int sig, __sighandler_t disp)
31
29
struct sigaction act, oact;
32
/* Check signal extents to protect __sigismember. */
33
if (disp == SIG_ERR || sig < 1 || sig >= NSIG)
35
40
/* Handle SIG_HOLD first. */
36
41
if (disp == SIG_HOLD)
38
/* Create an empty signal set. */
39
if (__sigemptyset (&set) < 0)
42
/* Add the specified signal. */
43
if (__sigaddset (&set, sig) < 0)
44
__sigaddset (&set, sig);
46
46
/* Add the signal set to the current signal mask. */
47
if (sigprocmask (SIG_BLOCK, &set, NULL) < 0)
47
sigprocmask (SIG_BLOCK, &set, NULL); /* can't fail */
52
51
#endif /* SIG_HOLD */
54
/* Check signal extents to protect __sigismember. */
55
if (disp == SIG_ERR || sig < 1 || sig >= NSIG)
53
memset(&act, 0, sizeof(act));
61
54
act.sa_handler = disp;
62
if (__sigemptyset (&act.sa_mask) < 0)
55
/* In Linux (as of 2.6.25), fails only if sig is SIGKILL or SIGSTOP */
65
56
if (sigaction (sig, &act, &oact) < 0)
68
/* Create an empty signal set. */
69
if (__sigemptyset (&set) < 0)
72
/* Add the specified signal. */
73
if (__sigaddset (&set, sig) < 0)
59
/* Create an empty signal set. Add the specified signal. */
61
__sigaddset (&set, sig);
76
63
/* Remove the signal set from the current signal mask. */
77
if (sigprocmask (SIG_UNBLOCK, &set, NULL) < 0)
64
sigprocmask (SIG_UNBLOCK, &set, NULL); /* can't fail */
80
66
return oact.sa_handler;