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
27 * Although most stuff should work under most POSIX like systems;
28 * some funcs might be very linux related.
29 * (But at least we use that lib currently under linux only.)
32 #ifndef _I2N_SIGNALFUNC_HPP_
33 #define _I2N_SIGNALFUNC_HPP_
37 // with pain in the stomach; the following include was added....:
38 // (since these includes a lot of #define's... what we usually don't want to have in C++ headers...)
39 #include <sys/types.h>
59 * base class for internal implementation classes.
65 }; // eo class SObject
67 } // eo namespace Detail
70 * @brief representation of system signal.
72 * This struct also provides constants for the usual system signals; so it is not necessary to include signal.h
73 * for obtaining the constants.
75 * Due to an appropriate cast operator instances of the class can be used in all places where
76 * a plain signal (i.e. an int) is expected.
80 static const int VOID;
83 #define SIG(s) static const int s
84 SIG(HUP); SIG(INT); SIG(QUIT); SIG(ILL); SIG(TRAP);
85 SIG(ABRT); SIG(IOT); SIG(BUS); SIG(FPE); SIG(KILL);
86 SIG(USR1); SIG(SEGV); SIG(USR2); SIG(PIPE); SIG(ALRM);
87 SIG(TERM); SIG(STKFLT); SIG(CLD); SIG(CHLD); SIG(CONT); SIG(STOP);
88 SIG(TSTP); SIG(TTIN); SIG(TTOU); SIG(URG); SIG(XCPU);
89 SIG(XFSZ); SIG(VTALRM); SIG(PROF); SIG(WINCH); SIG(POLL);
90 SIG(IO); SIG(PWR); SIG(SYS);
95 static int RT(int num=0);
99 Signal(int signal) : Value(signal) {}
101 operator int () const { return Value; }
102 }; // eo struct Signal
106 * @brief representation of signal codes.
108 * This struct provides constants for signal codes; so it is not necessary to include signal.h
109 * for obtaining the constants.
111 * Due to an appropriate cast operator instances of the class can be used in all places where
112 * a plain signal code (i.e. an int) is expected.
119 #define CODE(name) static const int name
120 CODE(USER); CODE(QUEUE); CODE(TIMER); CODE(MESGQ);
127 * @brief contains the codes for signal SIGILL
132 CODE(ILLOPC); CODE(ILLOPN); CODE(ILLADR); CODE(ILLTRP);
133 CODE(PRVOPC); CODE(PRVREG); CODE(COPROC); CODE(BADSTK);
139 * @brief contains the codes for signal SIGFPE
144 CODE(INTDIV); CODE(INTOVF); CODE(FLTDIV); CODE(FLTOVF);
145 CODE(FLTUND); CODE(FLTRES); CODE(FLTINV); CODE(FLTSUB);
151 * @brief contains the codes for signal SIGSEGV
156 CODE(MAPERR); CODE(ACCERR);
162 * @brief contains the codes for signal SIGBUS
167 CODE(ADRALN); CODE(ADRERR); CODE(OBJERR);
173 * @brief contains the codes for signal SIGTRAP
178 CODE(BRKPT); CODE(TRACE);
184 * @brief contains the codes for signal SIGCHLD
189 CODE(EXITED); CODE(KILLED); CODE(DUMPED); CODE(TRAPPED);
190 CODE(STOPPED); CODE(CONTINUED);
196 * @brief contains the codes for signal SIGPOLL
201 CODE(IN); CODE(OUT); CODE(MSG); CODE(ERR); CODE(PRI); CODE(HUP);
209 SignalCode(int code) : TheCode(code) {}
211 operator int () const { return TheCode; }
218 * @brief helper for blocking a (or some) signal(s) during an operation.
220 * This class blocks the given signals when constructed and resets the original block mask
223 class ScopedSignalBlocker
226 ScopedSignalBlocker(Signal sig);
227 ScopedSignalBlocker(Signal sig1, Signal sig2);
228 ScopedSignalBlocker(Signal sig1, Signal sig2, Signal sig3);
229 ScopedSignalBlocker(const std::vector<Signal>& sigs);
230 virtual ~ScopedSignalBlocker();
233 Detail::SObject* Implementation;
235 }; // eo class ScopedSignalBlocker
240 bool install_signal_handler(
245 bool install_signal_handler(
247 void(*handler)(int,struct siginfo*,void*)
250 bool ignore_signal(Signal sig);
251 bool install_default_signal_handler(Signal sig);
253 bool restore_signal_handler(Signal sig);
256 bool send_signal( pid_t pid, Signal signal);
259 } // eo namespace SysTools
260 } // eo namespace I2n