wibble  0.1.28
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 
16 struct ProcMask
17 {
18 #ifdef POSIX
19  sigset_t oldset;
20 #else
21 #define SIG_BLOCK 0 // FIXME, is this reasonable?
22 #endif
23  ProcMask(const sigset_t& newset, int how = SIG_BLOCK)
24  {
25 #ifdef POSIX
26  if (sigprocmask(how, &newset, &oldset) < 0)
27  throw wibble::exception::System("setting signal mask");
28 #else
29  assert_die();
30 #endif
31  }
33  {
34 #ifdef POSIX
35  if (sigprocmask(SIG_SETMASK, &oldset, NULL) < 0)
36  throw wibble::exception::System("restoring signal mask");
37 #endif
38  }
39 };
40 
41 struct Action
42 {
43  int signum;
44 #ifdef POSIX
45  struct sigaction oldact;
46 #endif
47 
48  Action(int signum, const struct sigaction& act) : signum(signum)
49  {
50 #ifdef POSIX
51  if (sigaction(signum, &act, &oldact) < 0)
52  throw wibble::exception::System("setting signal action");
53 #else
54  assert_die();
55 #endif
56  }
58  {
59 #ifdef POSIX
60  if (sigaction(signum, &oldact, NULL) < 0)
61  throw wibble::exception::System("restoring signal action");
62 #endif
63  }
64 };
65 
66 }
67 }
68 }
69 
70 // vim:set ts=4 sw=4:
71 #endif