1 /*
2 * stonith_signal.h: signal handling routines to be used by stonith
3 * plugin libraries
4 *
5 * Copyright (C) 2002 Horms <horms@verge.net.au>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22 #ifndef _STONITH_SIGNAL_H
23 #define _STONITH_SIGNAL_H
24
25 #include <signal.h>
26 #include <sys/signal.h>
27
28 int
29 stonith_signal_set_simple_handler(int sig, void (*handler)(int)
30 , struct sigaction *oldact);
31
32 int
stonith_signal_set_simple_handler(int sig,void (* handler)(int),struct sigaction * oldact)33 stonith_signal_set_simple_handler(int sig, void (*handler)(int)
34 , struct sigaction *oldact)
35 {
36 struct sigaction sa;
37 sigset_t mask;
38
39 (void)stonith_signal_set_simple_handler;
40 if(sigemptyset(&mask) < 0) {
41 return(-1);
42 }
43
44 sa.sa_handler = handler;
45 sa.sa_mask = mask;
46 sa.sa_flags = 0;
47
48 if(sigaction(sig, &sa, oldact) < 0) {
49 return(-1);
50 }
51
52 return(0);
53 }
54
55 #define STONITH_SIGNAL(_sig, _handler) \
56 stonith_signal_set_simple_handler((_sig), (_handler), NULL)
57 #ifdef HAVE_SIGIGNORE
58 #define STONITH_IGNORE_SIG(_sig) \
59 sigignore((_sig))
60 #else
61 #define STONITH_IGNORE_SIG(_sig) \
62 STONITH_SIGNAL((_sig), SIG_IGN)
63 #endif
64 #define STONITH_DEFAULT_SIG(_sig) STONITH_SIGNAL((_sig), SIG_DFL)
65
66 #define STONITH_KILL(_pid, _sig) kill((_pid), (_sig))
67
68 #endif /* _STONITH_SIGNAL_H */
69