1 /*
2 * PXE daemon - enable the remote booting of PXE enabled machines.
3 * Copyright (C) 2000 Tim Hurman (kano@kano.org.uk)
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 */
20 /******************************************************************************
21 * posix_signal.cc - a nice posix abstraction for a horrible subject *
22 ******************************************************************************/
23
24 #include "posix_signal.h"
25
26
27 /******************************************************************************
28 * Constructor *
29 ******************************************************************************/
Signal(LogFile * _log)30 Signal::Signal(LogFile *_log)
31 {
32 this->log = _log;
33 }
34
35
36 /******************************************************************************
37 * Destructor *
38 ******************************************************************************/
~Signal()39 Signal::~Signal()
40 {
41 }
42
43
44 /******************************************************************************
45 * Set - set a signal register *
46 ******************************************************************************/
47 int
Set(int SIGNAL,void (* ACTION)(int))48 Signal::Set(int SIGNAL, void (*ACTION) (int))
49 {
50 struct sigaction act;
51
52 /* declare what is going to be called when */
53 act.sa_handler = ACTION;
54
55 /* clear the structure's mask */
56 sigemptyset(&act.sa_mask);
57
58 /* set up some flags */
59 act.sa_flags = SA_NOCLDSTOP;
60 act.sa_flags &= ~SA_RESTART;
61
62 /* set the signal handler */
63 if(sigaction(SIGNAL, &act, NULL) < 0)
64 log->Event(LEVEL_ERR, "Signal::Set:sigaction()", 1,
65 strerror(errno));
66
67 /* all ok */
68 return(0);
69 }
70
71
72 /******************************************************************************
73 * Block - block a signal *
74 ******************************************************************************/
75 int
Block(int SIGNAL)76 Signal::Block(int SIGNAL)
77 {
78 sigset_t set;
79
80 /* initalise */
81 sigemptyset(&set);
82
83 /* add the SIGNAL to the set */
84 sigaddset(&set, SIGNAL);
85
86 /* block it */
87 if(sigprocmask(SIG_BLOCK, &set, NULL) < 0)
88 log->Event(LEVEL_ERR, "Signal::Block:sigprocmask()", 1,
89 strerror(errno));
90
91 /* done */
92 return(0);
93 }
94
95
96 /******************************************************************************
97 * UnBlock - unblock a signal *
98 ******************************************************************************/
99 int
UnBlock(int SIGNAL)100 Signal::UnBlock(int SIGNAL)
101 {
102 sigset_t set;
103
104 /* initalise */
105 sigemptyset(&set);
106
107 /* add the SIGNAL to the set */
108 sigaddset(&set, SIGNAL);
109
110 /* block it */
111 if(sigprocmask(SIG_UNBLOCK, &set, NULL) < 0)
112 log->Event(LEVEL_ERR, "Signal::UnBlock:sigprocmask()", 1,
113 strerror(errno));
114
115 /* done */
116 return(0);
117 }
118