2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
21 * @brief provides wrapper and tools for signal related stuff.
24 * @copyright © Copyright 2007-2008 by Intra2net AG
25 * @contact opensource@intra2net.com
28 * Although most stuff should work under most POSIX like systems;
29 * some funcs might be very linux related.
30 * (But at least we use that lib currently under linux only.)
33 #ifndef _I2N_SIGNALFUNC_HPP_
34 #define _I2N_SIGNALFUNC_HPP_
38 // with pain in the stomach; the following include was added....:
39 // (since these includes a lot of #define's... what we usually don't want to have in C++ headers...)
40 #include <sys/types.h>
60 * base class for internal implementation classes.
66 }; // eo class SObject
68 } // eo namespace Detail
71 * @brief representation of system signal.
73 * This struct also provides constants for the usual system signals; so it is not necessary to include signal.h
74 * for obtaining the constants.
76 * Due to an appropriate cast operator instances of the class can be used in all places where
77 * a plain signal (i.e. an int) is expected.
81 static const int VOID;
84 #define SIG(s) static const int s
85 SIG(HUP); SIG(INT); SIG(QUIT); SIG(ILL); SIG(TRAP);
86 SIG(ABRT); SIG(IOT); SIG(BUS); SIG(FPE); SIG(KILL);
87 SIG(USR1); SIG(SEGV); SIG(USR2); SIG(PIPE); SIG(ALRM);
88 SIG(TERM); SIG(STKFLT); SIG(CLD); SIG(CHLD); SIG(CONT); SIG(STOP);
89 SIG(TSTP); SIG(TTIN); SIG(TTOU); SIG(URG); SIG(XCPU);
90 SIG(XFSZ); SIG(VTALRM); SIG(PROF); SIG(WINCH); SIG(POLL);
91 SIG(IO); SIG(PWR); SIG(SYS);
96 static int RT(int num=0);
100 Signal(int signal) : Value(signal) {}
102 operator int () const { return Value; }
103 }; // eo struct Signal
107 * @brief representation of signal codes.
109 * This struct provides constants for signal codes; so it is not necessary to include signal.h
110 * for obtaining the constants.
112 * Due to an appropriate cast operator instances of the class can be used in all places where
113 * a plain signal code (i.e. an int) is expected.
120 #define CODE(name) static const int name
121 CODE(USER); CODE(QUEUE); CODE(TIMER); CODE(MESGQ);
128 * @brief contains the codes for signal SIGILL
133 CODE(ILLOPC); CODE(ILLOPN); CODE(ILLADR); CODE(ILLTRP);
134 CODE(PRVOPC); CODE(PRVREG); CODE(COPROC); CODE(BADSTK);
140 * @brief contains the codes for signal SIGFPE
145 CODE(INTDIV); CODE(INTOVF); CODE(FLTDIV); CODE(FLTOVF);
146 CODE(FLTUND); CODE(FLTRES); CODE(FLTINV); CODE(FLTSUB);
152 * @brief contains the codes for signal SIGSEGV
157 CODE(MAPERR); CODE(ACCERR);
163 * @brief contains the codes for signal SIGBUS
168 CODE(ADRALN); CODE(ADRERR); CODE(OBJERR);
174 * @brief contains the codes for signal SIGTRAP
179 CODE(BRKPT); CODE(TRACE);
185 * @brief contains the codes for signal SIGCHLD
190 CODE(EXITED); CODE(KILLED); CODE(DUMPED); CODE(TRAPPED);
191 CODE(STOPPED); CODE(CONTINUED);
197 * @brief contains the codes for signal SIGPOLL
202 CODE(IN); CODE(OUT); CODE(MSG); CODE(ERR); CODE(PRI); CODE(HUP);
210 SignalCode(int code) : TheCode(code) {}
212 operator int () const { return TheCode; }
219 * @brief helper for blocking a (or some) signal(s) during an operation.
221 * This class blocks the given signals when constructed and resets the original block mask
224 class ScopedSignalBlocker
227 ScopedSignalBlocker(Signal sig);
228 ScopedSignalBlocker(Signal sig1, Signal sig2);
229 ScopedSignalBlocker(Signal sig1, Signal sig2, Signal sig3);
230 ScopedSignalBlocker(const std::vector<Signal>& sigs);
231 virtual ~ScopedSignalBlocker();
234 Detail::SObject* Implementation;
236 }; // eo class ScopedSignalBlocker
241 bool install_signal_handler(
246 bool install_signal_handler(
248 void(*handler)(int,struct siginfo*,void*)
251 bool ignore_signal(Signal sig);
252 bool install_default_signal_handler(Signal sig);
254 bool restore_signal_handler(Signal sig);
257 bool send_signal( pid_t pid, Signal signal);
260 } // eo namespace SysTools
261 } // eo namespace I2n