libzypp 17.37.10

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
25 class SignalSaver
26 {
27 public:
28 SignalSaver( int signum_r, sighandler_t handler_r )
29 : _signum( signum_r )
30 { _orighandler = ::signal( signum_r, handler_r ); }
31 ~SignalSaver()
32 { ::signal( _signum, _orighandler ); }
33 private:
34 int _signum;
35 ::sighandler_t _orighandler;
36 };
37
41 class SigprocmaskSaver
42 {
43 public:
45 SigprocmaskSaver()
46 { ::sigprocmask( SIG_SETMASK, NULL, &_origmask ); }
47
48 ~SigprocmaskSaver()
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 }
59
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 }
67
68 bool pending( int signum_r )
69 {
70 ::sigset_t mask;
71 ::sigpending( &mask );
72 return ::sigismember( &mask, signum_r );
73 }
74
75 void suspend()
76 { ::sigsuspend( &_origmask ); }
77 private:
78 ::sigset_t _origmask;
79 };
80
82} // namespace zypp
84#endif // ZYPP_BASE_SIGNAL_H
zypp::SignalSaver::_orighandler
::sighandler_t _orighandler
Definition Signal.h:35
zypp::SignalSaver::SignalSaver
SignalSaver(int signum_r, sighandler_t handler_r)
Definition Signal.h:28
zypp::SignalSaver::~SignalSaver
~SignalSaver()
Definition Signal.h:31
zypp::SignalSaver::_signum
int _signum
Definition Signal.h:34
zypp::SigprocmaskSaver::~SigprocmaskSaver
~SigprocmaskSaver()
Dtor restoring the original sigprocmask.
Definition Signal.h:48
zypp::SigprocmaskSaver::block
void block(int signum_r)
Temporary block signal.
Definition Signal.h:52
zypp::SigprocmaskSaver::SigprocmaskSaver
SigprocmaskSaver()
Ctor saving the original sigprocmask.
Definition Signal.h:45
zypp::SigprocmaskSaver::pending
bool pending(int signum_r)
Whether signal delivery is pending.
Definition Signal.h:68
zypp::SigprocmaskSaver::unblock
void unblock(int signum_r)
Temporary unblock signal.
Definition Signal.h:60
zypp::SigprocmaskSaver::suspend
void suspend()
Wait for signals not blocked in original sigprocmask.
Definition Signal.h:75
zypp::SigprocmaskSaver::_origmask
::sigset_t _origmask
Definition Signal.h:78
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20