libzypp  17.14.0
Signal.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_SIGNAL_H
13 #define ZYPP_BASE_SIGNAL_H
14 
15 #include <csignal>
16 #include <iosfwd>
17 
19 namespace zypp
20 {
21 
26  {
27  public:
28  SignalSaver( int signum_r, sighandler_t handler_r )
29  : _signum( signum_r )
30  { _orighandler = ::signal( signum_r, handler_r ); }
32  { ::signal( _signum, _orighandler ); }
33  private:
34  int _signum;
35  ::sighandler_t _orighandler;
36  };
37 
42  {
43  public:
46  { ::sigprocmask( SIG_SETMASK, NULL, &_origmask ); }
49  { ::sigprocmask( SIG_SETMASK, &_origmask, NULL ); }
50  public:
52  void block( int signum_r )
53  {
54  ::sigset_t mask;
55  ::sigemptyset( & mask );
56  ::sigaddset( & mask, signum_r );
57  ::sigprocmask( SIG_BLOCK, &mask, NULL );
58  }
60  void unblock( int signum_r )
61  {
62  ::sigset_t mask;
63  ::sigemptyset( & mask );
64  ::sigaddset( & mask, signum_r );
65  ::sigprocmask( SIG_UNBLOCK, &mask, NULL );
66  }
68  bool pending( int signum_r )
69  {
70  ::sigset_t mask;
71  ::sigpending( &mask );
72  return ::sigismember( &mask, signum_r );
73  }
75  void suspend()
76  { ::sigsuspend( &_origmask ); }
77  private:
78  ::sigset_t _origmask;
79  };
80 
82 } // namespace zypp
84 #endif // ZYPP_BASE_SIGNAL_H
void block(int signum_r)
Temporary block signal.
Definition: Signal.h:52
Exception safe sigprocmask save/restore.
Definition: Signal.h:41
~SigprocmaskSaver()
Dtor restoring the original sigprocmask.
Definition: Signal.h:48
void unblock(int signum_r)
Temporary unblock signal.
Definition: Signal.h:60
::sighandler_t _orighandler
Definition: Signal.h:35
void suspend()
Wait for signals not blocked in original sigprocmask.
Definition: Signal.h:75
SigprocmaskSaver()
Ctor saving the original sigprocmask.
Definition: Signal.h:45
Exception safe signal handler save/restore.
Definition: Signal.h:25
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
SignalSaver(int signum_r, sighandler_t handler_r)
Definition: Signal.h:28
::sigset_t _origmask
Definition: Signal.h:78
bool pending(int signum_r)
Whether signal delivery is pending.
Definition: Signal.h:68