32 |
/** |
/** |
33 |
* Signal handeling routines. |
* Signal handeling routines. |
34 |
* |
* |
35 |
* @author W. Richard Stevens <heaven> |
* @author W. Richard Stevens |
36 |
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com> |
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com> |
37 |
* |
* |
38 |
* @version \$Id$ |
* @version \$Id$ |
74 |
|
|
75 |
|
|
76 |
/** |
/** |
77 |
* Set a handler for the alarm signal, |
* Set a collective thread signal block for signals honored by monit |
78 |
* SIGALRM using sigaction. |
* @param new The signal mask to use for the block |
79 |
|
* @param old The signal mask used to save the previous mask |
80 |
*/ |
*/ |
81 |
void set_alarm_handler(void *func) { |
void set_signal_block(sigset_t *new, sigset_t *old) { |
82 |
|
|
83 |
struct sigaction sa; |
sigemptyset(new); |
84 |
|
sigaddset(new, SIGINT); |
85 |
|
sigaddset(new, SIGUSR1); |
86 |
|
sigaddset(new, SIGTERM); |
87 |
|
pthread_sigmask(SIG_BLOCK, new, old); |
88 |
|
|
89 |
sa.sa_handler= func; |
} |
90 |
sa.sa_flags= 0; |
|
91 |
sigemptyset(&sa.sa_mask); |
|
92 |
sigaction(SIGALRM, &sa, NULL); |
/** |
93 |
|
* Set the thread signal mask back to the old mask |
94 |
|
* @param old The signal mask to restore |
95 |
|
*/ |
96 |
|
void unset_signal_block(sigset_t *old) { |
97 |
|
|
98 |
|
pthread_sigmask(SIG_SETMASK, old, NULL); |
99 |
|
|
100 |
} |
} |