| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# Gaudi::Utils::SignalMonitorSvc Class Reference

Implementation of Gaudi::ISignalMonitor. More...

Inheritance diagram for Gaudi::Utils::SignalMonitorSvc:

[legend]
Collaboration diagram for Gaudi::Utils::SignalMonitorSvc:

[legend]

List of all members.

## Public Types
typedef struct sigaction | handler_t
## Public Member Functions
void | monitorSignal (int signum, bool propagate)
| Declare a signal to be monitored.
void | ignoreSignal (int signum)
| Remove the specific signal handler for the requested signal, restoring the previous signal handler.
bool | gotSignal (int signum) const
| Check if the given signal has been received.
void | setSignal (int signum)
| Set the flag for the given signal, as if the signal was received.
void | clearSignal (int signum)
| Clear the flag for the given signal, so that a new occurrence can be identified.
| SignalMonitorSvc (const std::string &name, ISvcLocator *svcLoc)
| Initialize internal variables of the service and set the instance pointer.
virtual | ~SignalMonitorSvc ()
| Stop monitoring signals and clear the instance pointer.
## 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 SignalMonitorSvc * | instance ()
| Method to get the singleton instance.
static void | dispatcher (int signum)
| Signal handler function.
## Private Attributes
MonitoringMode | m_monitored [NSIG]
| Array of flags to keep track of monitored signals.
sig_atomic_t | m_caught [NSIG]
| Array of flags for received signals.
handler_t | m_defaultAction
| Helper variable for default signal action.
handler_t | m_oldActions [NSIG]
| List of replaced signal actions (for the recovery when disable the monitoring).
## Static Private Attributes
static SignalMonitorSvc * | s_instance = 0
| Pointer to the current instance.

## 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`[read]`

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.

    00112                           {
    00113         ignored,  //< the signal is not monitored
    00114         trap,     //< the signal is monitored and not propagated to previously registered handlers
    00115         propagate //< the signal is monitored and propagated to previously registered handlers
    00116       };

## 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.

    00085                                                                   : base_class(name, svcLoc) {
    00086 #ifdef _WIN32
    00087         m_defaultAction = SIG_DFL;
    00088 #else
    00089         m_defaultAction.sa_handler = SIG_DFL;
    00090         sigemptyset(&m_defaultAction.sa_mask);
    00091         m_defaultAction.sa_flags = 0;
    00092 #endif
    00093         for(int i = 0; i < NSIG; ++i){
    00094           m_caught[i] = 0;
    00095           m_monitored[i] = ignored;
    00096           m_oldActions[i] = m_defaultAction;
    00097         }
    00098
    00099         setInstance(this);
    00100       }

virtual Gaudi::Utils::SignalMonitorSvc::~SignalMonitorSvc | ( |  | ) | `[inline, virtual]`

Stop monitoring signals and clear the instance pointer.

Definition at line 103 of file SignalMonitorSvc.cpp.

    00103                                   {
    00104         for (int i = 0; i < NSIG; ++i) {
    00105           ignoreSignal(i);
    00106         }
    00107         setInstance(0);
    00108       }

## Member Function Documentation

void Gaudi::Utils::SignalMonitorSvc::monitorSignal | ( | int | signum,
|  | bool | propagate |
| ) |  |  | `[inline, virtual]`

Declare a signal to be monitored.

It installs a signal handler for the requested signal.

Implements ISignalMonitor.

Definition at line 36 of file SignalMonitorSvc.cpp.

    00036                                                      {
    00037         if (!m_monitored[signum]) {
    00038           handler_t sa;
    00039           handler_t oldact;
    00040 #ifdef _WIN32
    00041           sa = SignalMonitorSvc::dispatcher;
    00042           oldact = signal(signum, sa);
    00043 #else
    00044           sa.sa_handler = SignalMonitorSvc::dispatcher;
    00045           sigemptyset(&sa.sa_mask);
    00046           sa.sa_flags = 0;
    00047           sigaction(signum, &sa, &oldact);
    00048 #endif
    00049           m_oldActions[signum] = oldact;
    00050           m_monitored[signum] = (propagate) ? SignalMonitorSvc::propagate
    00051                                             : SignalMonitorSvc::trap;
    00052         }
    00053       }

void Gaudi::Utils::SignalMonitorSvc::ignoreSignal | ( | int | signum | ) | `[inline, virtual]`

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

Implements ISignalMonitor.

Definition at line 57 of file SignalMonitorSvc.cpp.

    00057                                     {
    00058         if (m_monitored[signum]) {
    00059 #ifdef _WIN32
    00060           (void) signal(signum, m_oldActions[signum]);
    00061 #else
    00062           sigaction(signum, &m_oldActions[signum], 0);
    00063 #endif
    00064           m_oldActions[signum] = m_defaultAction;
    00065           m_monitored[signum] = ignored;
    00066         }
    00067       }

bool Gaudi::Utils::SignalMonitorSvc::gotSignal | ( | int | signum | ) | const`[inline, virtual]`

Check if the given signal has been received.

Implements ISignalMonitor.

Definition at line 70 of file SignalMonitorSvc.cpp.

    00070                                        {
    00071         return m_caught[signum] != 0;
    00072       }

void Gaudi::Utils::SignalMonitorSvc::setSignal | ( | int | signum | ) | `[inline, virtual]`

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

Implements ISignalMonitor.

Definition at line 75 of file SignalMonitorSvc.cpp.

    00075                                  {
    00076         m_caught[signum] = 1;
    00077       }

void Gaudi::Utils::SignalMonitorSvc::clearSignal | ( | int | signum | ) | `[inline, virtual]`

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

Implements ISignalMonitor.

Definition at line 80 of file SignalMonitorSvc.cpp.

    00080                                    {
    00081         m_caught[signum] = 0;
    00082       }

void Gaudi::Utils::SignalMonitorSvc::i_handle | ( | int | signum | ) | `[inline, private]`

Definition at line 126 of file SignalMonitorSvc.cpp.

    00126                                 {
    00127         m_caught[signum] = 1;
    00128         if ( m_monitored[signum] == propagate &&
    00129 #ifdef _WIN32
    00130             m_oldActions[signum] != SIG_DFL
    00131 #else
    00132             m_oldActions[signum].sa_handler != SIG_DFL
    00133 #endif
    00134         ) {
    00135 #ifdef _WIN32
    00136           m_oldActions[signum](signum);
    00137 #else
    00138           m_oldActions[signum].sa_handler(signum);
    00139 #endif
    00140         }
    00141       }

static void Gaudi::Utils::SignalMonitorSvc::setInstance | ( | SignalMonitorSvc * | i | ) | `[inline, static, private]`

Definition at line 146 of file SignalMonitorSvc.cpp.

    00146                                                           {
    00147         s_instance = i;
    00148       }

static SignalMonitorSvc* Gaudi::Utils::SignalMonitorSvc::instance | ( |  | ) | `[inline, static, private]`

Method to get the singleton instance.

Bypass the serviceLocator for efficiency.

Definition at line 152 of file SignalMonitorSvc.cpp.

    00152                                                  {
    00153         return s_instance;
    00154       }

void Gaudi::Utils::SignalMonitorSvc::dispatcher | ( | int | signum | ) | `[static, private]`

Signal handler function.

Definition at line 161 of file SignalMonitorSvc.cpp.

    00161                                                {
    00162       if (instance()) instance()->i_handle(signum);
    00163     }

## Member Data Documentation

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.

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.

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 = 0`[static, private]`

Pointer to the current instance.

Definition at line 144 of file SignalMonitorSvc.cpp.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r9/GaudiUtils/src/component/SignalMonitorSvc.cpp