wibble  0.1.28
signal.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef WIBBLE_SYS_SIGNAL_H
00003 #define WIBBLE_SYS_SIGNAL_H
00004 
00005 #include <wibble/sys/macros.h>
00006 #include <wibble/exception.h>
00007 #include <signal.h>
00008 
00009 namespace wibble {
00010 namespace sys {
00011 namespace sig {
00012 
00016 struct ProcMask
00017 {
00018 #ifdef POSIX
00019     sigset_t oldset;
00020 #else
00021 #define SIG_BLOCK 0 // FIXME, is this reasonable?
00022 #endif
00023     ProcMask(const sigset_t& newset, int how = SIG_BLOCK)
00024     {
00025 #ifdef POSIX
00026         if (sigprocmask(how, &newset, &oldset) < 0)
00027             throw wibble::exception::System("setting signal mask");
00028 #else
00029                 assert_die();
00030 #endif
00031     }
00032     ~ProcMask()
00033     {
00034 #ifdef POSIX
00035         if (sigprocmask(SIG_SETMASK, &oldset, NULL) < 0)
00036             throw wibble::exception::System("restoring signal mask");
00037 #endif
00038     }
00039 };
00040 
00041 struct Action
00042 {
00043     int signum;
00044 #ifdef POSIX
00045     struct sigaction oldact;
00046 #endif
00047 
00048     Action(int signum, const struct sigaction& act) : signum(signum)
00049     {
00050 #ifdef POSIX
00051         if (sigaction(signum, &act, &oldact) < 0)
00052             throw wibble::exception::System("setting signal action");
00053 #else
00054                 assert_die();
00055 #endif
00056     }
00057     ~Action()
00058     {
00059 #ifdef POSIX
00060         if (sigaction(signum, &oldact, NULL) < 0)
00061             throw wibble::exception::System("restoring signal action");
00062 #endif
00063     }
00064 };
00065 
00066 }
00067 }
00068 }
00069 
00070 // vim:set ts=4 sw=4:
00071 #endif