Go to the documentation of this file.00001 #ifndef WIBBLE_SYS_SIGNAL_H
00002 #define WIBBLE_SYS_SIGNAL_H
00003
00004 #include <wibble/exception.h>
00005 #include <signal.h>
00006
00007 namespace wibble {
00008 namespace sys {
00009 namespace sig {
00010
00014 struct ProcMask
00015 {
00016 sigset_t oldset;
00017
00018 ProcMask(const sigset_t& newset, int how = SIG_BLOCK)
00019 {
00020 if (sigprocmask(how, &newset, &oldset) < 0)
00021 throw wibble::exception::System("setting signal mask");
00022 }
00023 ~ProcMask()
00024 {
00025 if (sigprocmask(SIG_SETMASK, &oldset, NULL) < 0)
00026 throw wibble::exception::System("restoring signal mask");
00027 }
00028 };
00029
00030 struct Action
00031 {
00032 int signum;
00033 struct sigaction oldact;
00034
00035 Action(int signum, const struct sigaction& act) : signum(signum)
00036 {
00037 if (sigaction(signum, &act, &oldact) < 0)
00038 throw wibble::exception::System("setting signal action");
00039 }
00040 ~Action()
00041 {
00042 if (sigaction(signum, &oldact, NULL) < 0)
00043 throw wibble::exception::System("restoring signal action");
00044 }
00045 };
00046
00047 }
00048 }
00049 }
00050
00051
00052 #endif