libzypp 17.31.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
19namespace 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:
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
Exception safe signal handler save/restore.
Definition: Signal.h:26
::sighandler_t _orighandler
Definition: Signal.h:35
SignalSaver(int signum_r, sighandler_t handler_r)
Definition: Signal.h:28
Exception safe sigprocmask save/restore.
Definition: Signal.h:42
~SigprocmaskSaver()
Dtor restoring the original sigprocmask.
Definition: Signal.h:48
void block(int signum_r)
Temporary block signal.
Definition: Signal.h:52
SigprocmaskSaver()
Ctor saving the original sigprocmask.
Definition: Signal.h:45
bool pending(int signum_r)
Whether signal delivery is pending.
Definition: Signal.h:68
void unblock(int signum_r)
Temporary unblock signal.
Definition: Signal.h:60
void suspend()
Wait for signals not blocked in original sigprocmask.
Definition: Signal.h:75
::sigset_t _origmask
Definition: Signal.h:78
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2