Gaudi::Utils::SignalMonitorSvc Class Reference

Implementation of Gaudi::ISignalMonitor. More...

Inheritance diagram for Gaudi::Utils::SignalMonitorSvc:
Collaboration diagram for Gaudi::Utils::SignalMonitorSvc:

Public Types

typedef struct sigaction handler_t
 
- Public Types inherited from extends< BASE, Interfaces >
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Public Member Functions

void monitorSignal (int signum, bool propagate)
 Declare a signal to be monitored. More...
 
void ignoreSignal (int signum)
 Remove the specific signal handler for the requested signal, restoring the previous signal handler. More...
 
bool gotSignal (int signum) const
 Check if the given signal has been received. More...
 
void setSignal (int signum)
 Set the flag for the given signal, as if the signal was received. More...
 
void clearSignal (int signum)
 Clear the flag for the given signal, so that a new occurrence can be identified. More...
 
 SignalMonitorSvc (const std::string &name, ISvcLocator *svcLoc)
 Initialize internal variables of the service and set the instance pointer. More...
 
virtual ~SignalMonitorSvc ()
 Stop monitoring signals and clear the instance pointer. More...
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Types

enum  MonitoringMode { ignored, trap, propagate }
 Possible monitoring modes. More...
 

Private Member Functions

void i_handle (int signum)
 

Static Private Member Functions

static void setInstance (SignalMonitorSvc *i)
 
static SignalMonitorSvcinstance ()
 Method to get the singleton instance. More...
 
static void dispatcher (int signum)
 Signal handler function. More...
 

Private Attributes

MonitoringMode m_monitored [NSIG]
 Array of flags to keep track of monitored signals. More...
 
sig_atomic_t m_caught [NSIG]
 Array of flags for received signals. More...
 
handler_t m_defaultAction
 Helper variable for default signal action. More...
 
handler_t m_oldActions [NSIG]
 List of replaced signal actions (for the recovery when disable the monitoring). More...
 

Static Private Attributes

static SignalMonitorSvcs_instance = nullptr
 Pointer to the current instance. More...
 

Detailed Description

Implementation of Gaudi::ISignalMonitor.

If instantiated, intercepts the system signals and keep track of the recorded ones.

The signal to be monitored have to be declared via the method monitorSignal(). It can be interrogated to check if a signal has been received.

Definition at line 26 of file SignalMonitorSvc.cpp.

Member Typedef Documentation

typedef struct sigaction Gaudi::Utils::SignalMonitorSvc::handler_t

Definition at line 31 of file SignalMonitorSvc.cpp.

Member Enumeration Documentation

enum Gaudi::Utils::SignalMonitorSvc::MonitoringMode
private

Possible monitoring modes.

Enumerator
ignored 
trap 
propagate 

Definition at line 112 of file SignalMonitorSvc.cpp.

112  {
113  ignored, //< the signal is not monitored
114  trap, //< the signal is monitored and not propagated to previously registered handlers
115  propagate //< the signal is monitored and propagated to previously registered handlers
116  };

Constructor & Destructor Documentation

Gaudi::Utils::SignalMonitorSvc::SignalMonitorSvc ( const std::string &  name,
ISvcLocator svcLoc 
)
inline

Initialize internal variables of the service and set the instance pointer.

Definition at line 85 of file SignalMonitorSvc.cpp.

85  : base_class(name, svcLoc) {
86 #ifdef _WIN32
87  m_defaultAction = SIG_DFL;
88 #else
89  m_defaultAction.sa_handler = SIG_DFL;
90  sigemptyset(&m_defaultAction.sa_mask);
91  m_defaultAction.sa_flags = 0;
92 #endif
93  for(int i = 0; i < NSIG; ++i){
94  m_caught[i] = 0;
97  }
98 
99  setInstance(this);
100  }
sig_atomic_t m_caught[NSIG]
Array of flags for received signals.
extends base_class
Typedef to this class.
Definition: extends.h:14
static void setInstance(SignalMonitorSvc *i)
MonitoringMode m_monitored[NSIG]
Array of flags to keep track of monitored signals.
handler_t m_oldActions[NSIG]
List of replaced signal actions (for the recovery when disable the monitoring).
handler_t m_defaultAction
Helper variable for default signal action.
list i
Definition: ana.py:128
virtual Gaudi::Utils::SignalMonitorSvc::~SignalMonitorSvc ( )
inlinevirtual

Stop monitoring signals and clear the instance pointer.

Definition at line 103 of file SignalMonitorSvc.cpp.

103  {
104  for (int i = 0; i < NSIG; ++i) {
105  ignoreSignal(i);
106  }
107  setInstance(0);
108  }
void ignoreSignal(int signum)
Remove the specific signal handler for the requested signal, restoring the previous signal handler...
static void setInstance(SignalMonitorSvc *i)
list i
Definition: ana.py:128

Member Function Documentation

void Gaudi::Utils::SignalMonitorSvc::clearSignal ( int  signum)
inline

Clear the flag for the given signal, so that a new occurrence can be identified.

Definition at line 80 of file SignalMonitorSvc.cpp.

80  {
81  m_caught[signum] = 0;
82  }
sig_atomic_t m_caught[NSIG]
Array of flags for received signals.
void Gaudi::Utils::SignalMonitorSvc::dispatcher ( int  signum)
staticprivate

Signal handler function.

Definition at line 161 of file SignalMonitorSvc.cpp.

161  {
162  if (instance()) instance()->i_handle(signum);
163  }
static SignalMonitorSvc * instance()
Method to get the singleton instance.
bool Gaudi::Utils::SignalMonitorSvc::gotSignal ( int  signum) const
inline

Check if the given signal has been received.

Definition at line 70 of file SignalMonitorSvc.cpp.

70  {
71  return m_caught[signum] != 0;
72  }
sig_atomic_t m_caught[NSIG]
Array of flags for received signals.
void Gaudi::Utils::SignalMonitorSvc::i_handle ( int  signum)
inlineprivate

Definition at line 126 of file SignalMonitorSvc.cpp.

126  {
127  m_caught[signum] = 1;
128  if ( m_monitored[signum] == propagate &&
129 #ifdef _WIN32
130  m_oldActions[signum] != SIG_DFL
131 #else
132  m_oldActions[signum].sa_handler != SIG_DFL
133 #endif
134  ) {
135 #ifdef _WIN32
136  m_oldActions[signum](signum);
137 #else
138  m_oldActions[signum].sa_handler(signum);
139 #endif
140  }
141  }
sig_atomic_t m_caught[NSIG]
Array of flags for received signals.
MonitoringMode m_monitored[NSIG]
Array of flags to keep track of monitored signals.
handler_t m_oldActions[NSIG]
List of replaced signal actions (for the recovery when disable the monitoring).
void Gaudi::Utils::SignalMonitorSvc::ignoreSignal ( int  signum)
inline

Remove the specific signal handler for the requested signal, restoring the previous signal handler.

Definition at line 57 of file SignalMonitorSvc.cpp.

57  {
58  if (m_monitored[signum]) {
59 #ifdef _WIN32
60  (void) signal(signum, m_oldActions[signum]);
61 #else
62  sigaction(signum, &m_oldActions[signum], 0);
63 #endif
64  m_oldActions[signum] = m_defaultAction;
65  m_monitored[signum] = ignored;
66  }
67  }
MonitoringMode m_monitored[NSIG]
Array of flags to keep track of monitored signals.
handler_t m_oldActions[NSIG]
List of replaced signal actions (for the recovery when disable the monitoring).
handler_t m_defaultAction
Helper variable for default signal action.
static SignalMonitorSvc* Gaudi::Utils::SignalMonitorSvc::instance ( )
inlinestaticprivate

Method to get the singleton instance.

Bypass the serviceLocator for efficiency.

Definition at line 152 of file SignalMonitorSvc.cpp.

152  {
153  return s_instance;
154  }
static SignalMonitorSvc * s_instance
Pointer to the current instance.
void Gaudi::Utils::SignalMonitorSvc::monitorSignal ( int  signum,
bool  propagate 
)
inline

Declare a signal to be monitored.

It installs a signal handler for the requested signal.

Definition at line 36 of file SignalMonitorSvc.cpp.

36  {
37  if (!m_monitored[signum]) {
38  handler_t sa;
39  handler_t oldact;
40 #ifdef _WIN32
42  oldact = signal(signum, sa);
43 #else
44  sa.sa_handler = SignalMonitorSvc::dispatcher;
45  sigemptyset(&sa.sa_mask);
46  sa.sa_flags = 0;
47  sigaction(signum, &sa, &oldact);
48 #endif
49  m_oldActions[signum] = oldact;
52  }
53  }
static void dispatcher(int signum)
Signal handler function.
MonitoringMode m_monitored[NSIG]
Array of flags to keep track of monitored signals.
handler_t m_oldActions[NSIG]
List of replaced signal actions (for the recovery when disable the monitoring).
static void Gaudi::Utils::SignalMonitorSvc::setInstance ( SignalMonitorSvc i)
inlinestaticprivate

Definition at line 146 of file SignalMonitorSvc.cpp.

146  {
147  s_instance = i;
148  }
static SignalMonitorSvc * s_instance
Pointer to the current instance.
list i
Definition: ana.py:128
void Gaudi::Utils::SignalMonitorSvc::setSignal ( int  signum)
inline

Set the flag for the given signal, as if the signal was received.

Definition at line 75 of file SignalMonitorSvc.cpp.

75  {
76  m_caught[signum] = 1;
77  }
sig_atomic_t m_caught[NSIG]
Array of flags for received signals.

Member Data Documentation

sig_atomic_t Gaudi::Utils::SignalMonitorSvc::m_caught[NSIG]
private

Array of flags for received signals.

Definition at line 120 of file SignalMonitorSvc.cpp.

handler_t Gaudi::Utils::SignalMonitorSvc::m_defaultAction
private

Helper variable for default signal action.

Definition at line 122 of file SignalMonitorSvc.cpp.

MonitoringMode Gaudi::Utils::SignalMonitorSvc::m_monitored[NSIG]
private

Array of flags to keep track of monitored signals.

Definition at line 118 of file SignalMonitorSvc.cpp.

handler_t Gaudi::Utils::SignalMonitorSvc::m_oldActions[NSIG]
private

List of replaced signal actions (for the recovery when disable the monitoring).

Definition at line 124 of file SignalMonitorSvc.cpp.

Gaudi::Utils::SignalMonitorSvc * Gaudi::Utils::SignalMonitorSvc::s_instance = nullptr
staticprivate

Pointer to the current instance.

Definition at line 144 of file SignalMonitorSvc.cpp.


The documentation for this class was generated from the following file: