ATLAS Offline Software
|
Utilities for handling signals and fatal errors. More...
#include <SealSignal.h>
Public Types | |
typedef bool(* | QuitHook) (int sig, siginfo_t *info, void *x) |
Application clean-up hook invoked before #quit(int , siginfo_t *, void *) exits from program termination signals (SIGHUP, SIGTERM or SIGQUIT). More... | |
typedef bool(* | FatalHook) (int sig, siginfo_t *info, void *x) |
Application hook to run in fatal(). More... | |
typedef void(* | FatalReturn) (int sig, siginfo_t *info, void *x) |
Application hook to jump back to the main program from a fatal signal, for example using #siglongjmp. More... | |
typedef void(* | HandlerType) (int sig, siginfo_t *info, void *extra) |
Signal handler type. More... | |
Static Public Member Functions | |
static const char * | name (int sig) |
Return the name of the signal number sig. More... | |
static HandlerType | handler (int sig, sigset_t *mask=0) |
Return the current handler for signal number sig and its blocked signals in mask (if non-null). More... | |
static HandlerType | handle (int sig, HandlerType handler, const sigset_t *blockMask=0) |
Install a new signal handler handler for signal number sig and returns the old handler. More... | |
static void | revert (int sig) |
Revert the signal number sig back to its default behaviour. More... | |
static void | ignore (int sig) |
Ignore the signal number sig. More... | |
static void | block (int sig, bool sense) |
Block or unblock the signal number sig. More... | |
static void | block (const sigset_t *mask, bool sense) |
Block or unblock the signals specified by mask. More... | |
static void | mask (const sigset_t *mask, sigset_t *old=0) |
Set the list of currently blocked signals to mask and return the old setting in old (if non-null). More... | |
static int | raise (int sig) |
Raise the signal number sig. More... | |
static int | kill (pid_t process, int sig) |
Send the signal sig to process identified by process. More... | |
static int | queue (int sig, int value=0) |
Queue signal sig for this process with additional data value. More... | |
static int | queue (int sig, void *value) |
Queue signal sig for this process with additional data value. More... | |
static int | queue (pid_t process, int sig, int value=0) |
Queue signal sig with additional data value for process. More... | |
static int | queue (pid_t process, int sig, void *value) |
Queue signal sig with additional data value for process. More... | |
static bool | pending (int sig) |
Check if sig is pending for this process. More... | |
static void | pending (sigset_t *mask) |
Return in mask the list of signals pending for this process. More... | |
static void | suspend (const sigset_t *mask) |
Temporarily replace the signal mask of the process with mask and then suspend until a signal is received. More... | |
static bool | wait (int sig, siginfo_t *info=0, long msecs=-1) |
Suspend the thread waiting for signal sig at most msecs milliseconds. More... | |
static int | wait (const sigset_t *mask, siginfo_t *info=0, long msecs=-1) |
Suspend the thread waiting for signals specified by mask for at most msecs milliseconds. More... | |
static void handleQuit | ATLAS_NOT_THREAD_SAFE (QuitHook hook=0) |
static QuitHook handleQuitHook | ATLAS_NOT_THREAD_SAFE (void) |
static void quit | ATLAS_NOT_THREAD_SAFE (int sig, siginfo_t *info, void *x) |
static void handleFatal | ATLAS_NOT_THREAD_SAFE (const char *applicationName=0, IOFD fd=IOFD_INVALID, FatalHook hook=0, FatalReturn mainreturn=0, unsigned options=FATAL_DEFAULT) |
static IOFD handleFatalFd | ATLAS_NOT_THREAD_SAFE (void) |
static FatalHook handleFatalHook | ATLAS_NOT_THREAD_SAFE (void) |
static FatalReturn handleFatalReturn | ATLAS_NOT_THREAD_SAFE (void) |
static unsigned handleFatalOptions | ATLAS_NOT_THREAD_SAFE (void) |
static void fatal | ATLAS_NOT_THREAD_SAFE (int sig, siginfo_t *info, void *x) |
static bool fatalDump | ATLAS_NOT_THREAD_SAFE (int sig, siginfo_t *info, void *x, IOFD fd, unsigned options) |
static bool fatalDump | ATLAS_NOT_THREAD_SAFE (int sig, siginfo_t *info, void *x) |
static int fatalLevel | ATLAS_NOT_THREAD_SAFE (void) |
static bool crashed | ATLAS_NOT_THREAD_SAFE (void) |
static void | dumpInfo (IOFD fd, char *buf, unsigned int buf_size, int sig, const siginfo_t *info) |
Utility function to dump the signal info descriptor for signal sig, as obtained for instance through signal handler parameters or wait(). More... | |
static void | dumpMemory (IOFD fd, char *buf, unsigned int buf_size, const void *data, size_t n) |
Utility function to dump memory section from data for n bytes. More... | |
static unsigned long | dumpContext (IOFD fd, char *buf, unsigned int buf_size, const void *context) |
Utility function to dump the process context, as obtained for instance through signal handler parameters, unix getcontext() or Windows GetThreadContext() . More... | |
static const char * | describe (int sig, int code) |
Return the description for signal info code code for signal number sig. More... | |
Static Public Attributes | |
static const int | USR1_DUMP_CORE = 1 |
Option that instructs #fatal(int, siginfo_t *, void *) to call #coredump() on SIGUSR1. More... | |
static const int | FATAL_ON_QUIT = 2 |
Option to make SIGHUP, SIGTERM and SIGQUIT fatal instead of just #quit(int , siginfo_t *, void *) signals. More... | |
static const int | FATAL_ON_INT = 4 |
Option to make SIGINT fatal. More... | |
static const int | FATAL_DUMP_CORE = 8 |
Option to make #fatal(int, siginfo_t *, void *) dump a core file before crashing. More... | |
static const int | FATAL_DUMP_SIG = 16 |
Option to make #fataldump(int, siginfo_t *, void *) (invoked by #fatal(int, siginfo_t *, void *)) to dump the signal name (as reported by name()). More... | |
static const int | FATAL_DUMP_STACK = 32 |
Option to make #fataldump(int, siginfo_t *, void *) (invoked by #fatal(int, siginfo_t *, void *)) to dump stack backtrace for the offending code location. More... | |
static const int | FATAL_DUMP_LIBS = 64 |
Option to make #fataldump(int sig, siginfo_t *, void *) (invoked by #fatal(int, siginfo_t *, void *)) to dump the list of currently loaded shared libraries. More... | |
static const int | FATAL_DUMP_CONTEXT = 128 |
Option to make #fataldump(int, siginfo_t *, void *) (invoked by #fatal(int, siginfo_t *, void *)) to dump the machine context (registers etc.) from the fault position. More... | |
static const int | FATAL_AUTO_EXIT = 256 |
Option to make #fatal(int, siginfo_t *, void *) exit via #quit(int , siginfo_t *, void *). More... | |
static const int | FATAL_DEFAULT |
Default options to #handleFatal(const char *, IOFD fd, FatalHook, FatalReturn, unsigned. More... | |
Static Private Member Functions | |
static void | trampoline (int sig) |
Internal signal handler trampoline to convert handler arguments to look more like POSIX signals. More... | |
Static Private Attributes | |
static bool | s_crashed = false |
Indicator that the application has been crashed: that a fatal signal has been delivered. More... | |
static int | s_inFatal = 0 |
Indicator that we are currently executing inside #fatal(). More... | |
static std::atomic< unsigned long > | s_lastSP |
Used to switch to a raw stack dump if we crash during a backtrace. More... | |
static const char * | s_applicationName = 0 |
The current application name. More... | |
static IOFD | s_fatalFd = IOFD_INVALID |
The output file descriptor for #fataldump(). More... | |
static FatalHook | s_fatalHook = 0 |
The application handler hook for fatal signals. More... | |
static FatalReturn | s_fatalReturn = 0 |
The application main return hook for fatal signals. More... | |
static unsigned | s_fatalOptions = 0 |
The current fatal signal handling options. More... | |
static QuitHook | s_quitHook = 0 |
The application handler hook for quitting-related signals. More... | |
static HandlerType | s_trampolines [NSIG] |
Actual signal handlers when POSIX signals are not available. More... | |
Utilities for handling signals and fatal errors.
FIXME: POSIX single-threaded vs. multi-threaded signals?
The fatal error handling is largely inspired by code in DDD, the Data Display Debugger, and by the examples in GNU libc manual.
Definition at line 100 of file SealSignal.h.
Application hook to run in fatal().
The hook should return true
if the signal handler should proceed to die. sig is the signal number, or its negative if core was dumped and, as far as can determined, successfully produced.
The fatal hooks should, if possible, perform clean-ups similar to QuitHook. The application may achieve this by actually using the quit by setting FATAL_AUTO_EXIT for #handleFatal(const char *, IOFD fd, FatalHook, FatalReturn, unsigned), or it could reuse an internal function in both handlers.
Definition at line 176 of file SealSignal.h.
Application hook to jump back to the main program from a fatal signal, for example using #siglongjmp.
It must never return. sig is the signal number, or its negative if core was dumped and, as far as can determined, successfully produced.
Definition at line 182 of file SealSignal.h.
typedef void(* Athena::Signal::HandlerType) (int sig, siginfo_t *info, void *extra) |
Signal handler type.
This is defined explicitly and does not necessarily match the system's concept of signal handler type. If necessary, suitable trampolines are used internally to make sure the arguments make sense.
sig | The signal number. |
info | Pointer to signal info. This pointer will be null on platforms that do not support POSIX signals. |
extra | Extra argument, e.g. the fault address. This pointer will be null on platforms that do not support POSIX signals. |
Definition at line 196 of file SealSignal.h.
Application clean-up hook invoked before #quit(int , siginfo_t *, void *) exits from program termination signals (SIGHUP, SIGTERM or SIGQUIT).
The handler should return true
if the signal handler should proceed to exit the application. Note that certain options to #handlFatal() cause this hook to be invoked for fatal signals. If such behaviour is enabled, be sure to check the #crashed() status before deciding to let the application to continue.
The quit hook should take care of resetting terminal modes, killing child processes, removing lock files, and so forth.
Definition at line 165 of file SealSignal.h.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Block or unblock the signals specified by mask.
The signals are blocked if sense is true
, unblocked otherwise. This function is implemented only on systems with POSIX signals.
Definition at line 353 of file SealSignal.cxx.
|
static |
Block or unblock the signal number sig.
The signal is blocked if sense is true
, unblocked otherwise. This function is implemented only on systems with POSIX signals.
Definition at line 338 of file SealSignal.cxx.
|
static |
Return the description for signal info code code for signal number sig.
The code should come from siginfo_t::si_code
.
Definition at line 968 of file SealSignal.cxx.
|
static |
Utility function to dump the process context, as obtained for instance through signal handler parameters, unix getcontext()
or Windows GetThreadContext()
.
The output is written directly to the file descriptor fd, using buf as the formatting buffer.
Returns SP if we can find it, else null.
Definition at line 1206 of file SealSignal.cxx.
|
static |
Utility function to dump the signal info descriptor for signal sig, as obtained for instance through signal handler parameters or wait().
The output is written directly to the file descriptor fd, using buf as the formatting buffer.
Definition at line 1084 of file SealSignal.cxx.
|
static |
Utility function to dump memory section from data for n bytes.
Used to dump machine context on platforms where we don't know any better. The output is written directly to the file descriptor fd, using buf as the formatting buffer.
Definition at line 1185 of file SealSignal.cxx.
|
static |
Install a new signal handler handler for signal number sig and returns the old handler.
This method uses the POSIX signal handling primitives if they are available, failing which falling back to the C standard signal()
function.
When POSIX signals are used, signals other than sig are blocked according to blockMask (if null, no change is made) during the execution of handler. Note that the signal itself is always blocked during the handler execution and need not be mentioned in the mask explicitly. System calls are made restartable although this has little impact as this library always restarts interrupted system calls automatically despite the signal handling settings.
(FIXME: Expose option SA_NOCLDSTOP, SA_ONSTACK?) (FIXME: Threads vs. signals)
Definition at line 277 of file SealSignal.cxx.
|
static |
Return the current handler for signal number sig and its blocked signals in mask (if non-null).
Definition at line 236 of file SealSignal.cxx.
|
static |
|
static |
Send the signal sig to process identified by process.
Implemented only on unixen.
Definition at line 389 of file SealSignal.cxx.
Set the list of currently blocked signals to mask and return the old setting in old (if non-null).
This function is implemented only on systems with POSIX signals.
Definition at line 365 of file SealSignal.cxx.
|
static |
Return the name of the signal number sig.
The returned memory is statically allocated and must not be freed.
Definition at line 216 of file SealSignal.cxx.
|
static |
|
static |
Return in mask the list of signals pending for this process.
Definition at line 484 of file SealSignal.cxx.
|
static |
Queue signal sig for this process with additional data value.
Implemented only on systems with POSIX real-time signals.
Definition at line 446 of file SealSignal.cxx.
|
static |
Queue signal sig for this process with additional data value.
Implemented only on systems with POSIX real-time signals.
Definition at line 463 of file SealSignal.cxx.
|
static |
Queue signal sig with additional data value for process.
Implemented only on systems with POSIX real-time signals.
Definition at line 411 of file SealSignal.cxx.
|
static |
Queue signal sig with additional data value for process.
Implemented only on systems with POSIX real-time signals.
Definition at line 429 of file SealSignal.cxx.
|
static |
|
static |
Revert the signal number sig back to its default behaviour.
Definition at line 326 of file SealSignal.cxx.
Temporarily replace the signal mask of the process with mask and then suspend until a signal is received.
Definition at line 500 of file SealSignal.cxx.
|
staticprivate |
Internal signal handler trampoline to convert handler arguments to look more like POSIX signals.
The actual handler must have been installed into s_trampolines by handle().
Definition at line 203 of file SealSignal.cxx.
Suspend the thread waiting for signals specified by mask for at most msecs milliseconds.
If msecs is negative (the default), waits until a signal is delivered. Otherwise waits up to the specified time limit. Returns the number of the signal that was received, or -1 if the time limit expired. If info is given, fills it with the information that the handler would have otherwise been given. Note that the signals must be blocked (in a multi-threaded application in all the threads, not just the calling one) and not be ignored before calling this function; if a handler is registered, it won't be called. Implemented only on systems with POSIX real-time signals.
Definition at line 562 of file SealSignal.cxx.
|
static |
Suspend the thread waiting for signal sig at most msecs milliseconds.
If msecs is negative (the default), waits until a signal is delivered. Otherwise waits up to the specified time limit. Returns true
if the signal was received. Note that the signal must be blocked (in a multi-threaded application in all the threads, not just the calling one) and not be ignored before calling this function; if a handler is registered, it won't be called. Implemented only on systems with POSIX real-time signals.
Definition at line 515 of file SealSignal.cxx.
|
static |
Option to make #fatal(int, siginfo_t *, void *) exit via #quit(int , siginfo_t *, void *).
This will cause all the application clean-up hook to run.
Definition at line 142 of file SealSignal.h.
|
static |
Default options to #handleFatal(const char *, IOFD fd, FatalHook, FatalReturn, unsigned.
Definition at line 145 of file SealSignal.h.
|
static |
Option to make #fataldump(int, siginfo_t *, void *) (invoked by #fatal(int, siginfo_t *, void *)) to dump the machine context (registers etc.) from the fault position.
Definition at line 138 of file SealSignal.h.
|
static |
Option to make #fatal(int, siginfo_t *, void *) dump a core file before crashing.
Definition at line 122 of file SealSignal.h.
|
static |
Option to make #fataldump(int sig, siginfo_t *, void *) (invoked by #fatal(int, siginfo_t *, void *)) to dump the list of currently loaded shared libraries.
Definition at line 134 of file SealSignal.h.
|
static |
Option to make #fataldump(int, siginfo_t *, void *) (invoked by #fatal(int, siginfo_t *, void *)) to dump the signal name (as reported by name()).
Definition at line 126 of file SealSignal.h.
|
static |
Option to make #fataldump(int, siginfo_t *, void *) (invoked by #fatal(int, siginfo_t *, void *)) to dump stack backtrace for the offending code location.
Definition at line 130 of file SealSignal.h.
|
static |
Option to make SIGINT fatal.
It will still just quit, not crash.
Definition at line 119 of file SealSignal.h.
|
static |
Option to make SIGHUP, SIGTERM and SIGQUIT fatal instead of just #quit(int , siginfo_t *, void *) signals.
Definition at line 115 of file SealSignal.h.
|
staticprivate |
|
staticprivate |
Indicator that the application has been crashed: that a fatal signal has been delivered.
Definition at line 273 of file SealSignal.h.
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
Indicator that we are currently executing inside #fatal().
Used to protect against signals delivered during recovery attempts.
Definition at line 274 of file SealSignal.h.
|
staticprivate |
Used to switch to a raw stack dump if we crash during a backtrace.
Definition at line 275 of file SealSignal.h.
|
staticprivate |
The application handler hook for quitting-related signals.
Definition at line 281 of file SealSignal.h.
|
staticprivate |
Actual signal handlers when POSIX signals are not available.
These are required so that we can send pass correct (= null) arguments to the registered handler when the system is not passing anything, or garbage. If this happens, handle() will register trampoline() as the signal handler and register the signal in this table, and trampoline just looks the actual handler here.
Definition at line 283 of file SealSignal.h.
|
static |
Option that instructs #fatal(int, siginfo_t *, void *) to call #coredump() on SIGUSR1.
This is merely a request to drop a core
; no attempt is made to guarantee success. Failure may result for example for lack of permissions, for lack of disk space, or due to low resource limits. Please note that core
files can only be created on unixen. Note also that dropping a core is a security risk and should never be enabled in setuid or setgid programs or for production applications.
Definition at line 111 of file SealSignal.h.