Loading [MathJax]/extensions/tex2jax.js
Go to the documentation of this file.
39 typedef void( __cdecl*
handler_t )( int );
52 oldact = signal( signum, sa );
55 sigemptyset( &sa.sa_mask );
57 sigaction( signum, &sa, &oldact );
96 for (
int i = 0; i < NSIG; ++i ) {
183 const char* sig_desc(
int signum ) {
184 if ( signum >= NSIG || signum < 0 )
return nullptr;
190 return "Illegal instruction";
192 return "Floating point exception";
194 return "Segmentation fault";
198 return "Trace/breakpoint trap";
205 return strsignal( signum );
213 static const SigMap& instance() {
218 inline const std::string&
name(
int signum )
const {
return m_num2id[signum]; }
220 inline const std::string& desc(
int signum )
const {
return m_num2desc[signum]; }
222 inline int signum(
const std::string& str )
const {
223 auto it = m_name2num.
find( str );
224 return it != m_name2num.end() ? it->second : -1;
231 #define addSignal( id ) i_addSignal( id, #id );
320 inline void i_addSignal(
int signum,
const char* signame ) {
321 m_num2id[signum] = signame;
322 m_name2num[signame] = signum;
323 const char* desc = sig_desc( signum );
325 m_num2desc[signum] = desc;
326 m_name2num[desc] = signum;
348 using extends::extends;
352 std::string serviceName(
"Gaudi::Utils::SignalMonitorSvc" );
355 error() <<
"Cannot retrieve " << serviceName <<
endmsg;
358 serviceName =
"IncidentSvc";
361 error() <<
"Cannot retrieve " << serviceName <<
endmsg;
367 warning() <<
"Cannot retrieve IProperty interface of ApplicationMgr, "
368 "the return code will not be changed"
374 if ( sigid.first >= 0 ) {
m_signals[sigid.first] = sigid.second; }
376 debug() <<
"Stopping on the signals:" <<
endmsg;
377 const SigMap& sigmap( SigMap::instance() );
379 debug() <<
"\t" << sigmap.name(
s.first ) <<
": " << sigmap.desc(
s.first ) <<
" (" <<
s.first <<
")";
380 if (
s.second ) debug() <<
" propagated";
386 debug() <<
"Register to the IncidentSvc" <<
endmsg;
387 m_incidentSvc->addListener(
this, IncidentType::BeginEvent );
391 m_incidentSvc->removeListener(
this, IncidentType::BeginEvent );
404 const SigMap& sigmap( SigMap::instance() );
407 warning() <<
"Received signal '" << sigmap.name(
s.first ) <<
"' (" <<
s.first;
409 if ( !desc.
empty() ) warning() <<
", " << desc;
410 warning() <<
")" <<
endmsg;
415 error() <<
"Could not set return code of the application (" <<
SignalOffset +
s.first <<
")" <<
endmsg;
421 warning() <<
"Scheduling a stop" <<
endmsg;
422 ep->stopRun().ignore();
424 warning() <<
"Cannot stop the processing because the IEventProcessor interface cannot be retrieved."
436 {
"SIGINT",
"SIGXCPU" },
437 "List of signal names or numbers to use to schedule a stop. "
438 "If the signal is followed by a '+' the signal is propagated the previously "
439 "registered handler (if any)." };
452 debug() <<
"Decoding signal declaration '" << sig <<
"'" <<
endmsg;
453 if ( sig.
empty() || sig ==
"+" ) {
454 debug() <<
"Empty signal, ignored" <<
endmsg;
455 return { -1,
false };
457 const SigMap& sigmap( SigMap::instance() );
459 bool propagate =
false;
461 if ( signal[signal.size() - 1] ==
'+' ) {
462 debug() <<
"Must be propagated to previously registered signal handlers" <<
endmsg;
464 signal.erase( signal.size() - 1, 1 );
473 signum = sigmap.signum( signal );
476 warning() <<
"Cannot understand signal identifier '" << sig <<
"', ignored" <<
endmsg;
478 verbose() <<
"Matched signal '" << sigmap.name( signum ) <<
"' (" << signum;
483 return { signum, propagate };
sig_atomic_t m_caught[NSIG]
Array of flags for received signals.
constexpr int SignalOffset
handler_t m_oldActions[NSIG]
List of replaced signal actions (for the recovery when disable the monitoring).
StatusCode initialize() override
void monitorSignal(int signum, bool propagate) override
Declare a signal to be monitored.
StatusCode initialize() override
std::map< int, bool > m_signals
Map of monitored signal numbers to the flag telling if they have to be propagated or not.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Gaudi::Property< std::vector< std::string > > m_usedSignals
List of signal names or numbers (encoded as strings) to use to schedule a stop.
Gaudi::Utils::SignalMonitorSvc g_u_sms
static SignalMonitorSvc * s_instance
Pointer to the current instance.
std::pair< int, bool > i_decodeSignal(const std::string &sig)
Function to translate the signal name to the signal number.
static void dispatcher(int signum)
Signal handler function.
StatusCode finalize() override
void i_handle(int signum)
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
~SignalMonitorSvc() override
Stop monitoring signals and clear the instance pointer.
const std::string & name() const override
Retrieve name of the service
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
MonitoringMode
Possible monitoring modes.
MonitoringMode m_monitored[NSIG]
Array of flags to keep track of monitored signals.
void ignoreSignal(int signum) override
Remove the specific signal handler for the requested signal, restoring the previous signal handler.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Service that stop the processing if a signal is received.
Base class used to extend a class implementing other interfaces.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Implementation of Gaudi::ISignalMonitor.
StatusCode finalize() override
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
static void setInstance(SignalMonitorSvc *i)
constexpr static const auto SUCCESS
SignalMonitorSvc(const std::string &name, ISvcLocator *svcLoc)
Initialize internal variables of the service and set the instance pointer.
#define DECLARE_COMPONENT(type)
void setSignal(int signum) override
Set the flag for the given signal, as if the signal was received.
bool m_stopRequested
Flag to remember if the stop has been requested because of a signal.
void handle(const Incident &) override
SmartIF< IProperty > m_appProperty
Pointer to the interface to set the return code of the application.
static SignalMonitorSvc * instance()
Method to get the singleton instance.
constexpr static const auto FAILURE
handler_t m_defaultAction
Helper variable for default signal action.
struct sigaction handler_t
void clearSignal(int signum) override
Clear the flag for the given signal, so that a new occurrence can be identified.
SmartIF< Gaudi::ISignalMonitor > m_signalMonitor
Pointer to the signal monitor service.
Implementation of property with value of concrete type.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator
bool gotSignal(int signum) const override
Check if the given signal has been received.