wibble  1.1
signal.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 #ifndef WIBBLE_SYS_SIGNAL_H
3 #define WIBBLE_SYS_SIGNAL_H
4 
5 #include <wibble/sys/macros.h>
6 #include <wibble/exception.h>
7 #include <signal.h>
8 
9 namespace wibble {
10 namespace sys {
11 namespace sig {
12 
13 #ifdef POSIX
14 
18 struct ProcMask
19 {
20  sigset_t oldset;
21  ProcMask(const sigset_t& newset, int how = SIG_BLOCK)
22  {
23  if (sigprocmask(how, &newset, &oldset) < 0)
24  throw wibble::exception::System("setting signal mask");
25  }
26 
27  ~ProcMask()
28  {
29  if (sigprocmask(SIG_SETMASK, &oldset, NULL) < 0)
30  throw wibble::exception::System("restoring signal mask");
31  }
32 };
33 
34 struct Action
35 {
36  int signum;
37  struct sigaction oldact;
38 
39  Action(int signum, const struct sigaction& act) : signum(signum)
40  {
41  if (sigaction(signum, &act, &oldact) < 0)
42  throw wibble::exception::System("setting signal action");
43  }
44  ~Action()
45  {
46  if (sigaction(signum, &oldact, NULL) < 0)
47  throw wibble::exception::System("restoring signal action");
48  }
49 };
50 
51 #endif
52 
53 }
54 }
55 }
56 
57 // vim:set ts=4 sw=4:
58 #endif