#include <Iguana/Utilities/classlib/utils/Signal.h>
Public Types | |
typedef bool(* | FatalHook )(int sig, siginfo_t *info, void *x) |
Application hook to run in fatal(). | |
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. | |
typedef void(* | HandlerType )(int sig, siginfo_t *info, void *extra) |
Signal handler type. | |
typedef bool(* | QuitHook )(int sig, siginfo_t *info, void *x) |
Application clean-up hook invoked before quit() exits from program termination signals (SIGHUP, SIGTERM or SIGQUIT). | |
Static Public Member Functions | |
static void | block (const sigset_t *mask, bool sense) |
static void | block (int sig, bool sense) |
static bool | crashed (void) |
static void | dumpContext (IOFD fd, char *buf, const void *context) |
static void | dumpInfo (IOFD fd, char *buf, int sig, const siginfo_t *info) |
static void | dumpMemory (IOFD fd, char *buf, const void *data, size_t n) |
static void | fatal (int sig, siginfo_t *info, void *x) |
static bool | fatalDump (int sig, siginfo_t *info, void *x) |
static int | fatalLevel (void) |
static HandlerType | handle (int sig, HandlerType handler, const sigset_t *blockMask=0) |
static void | handleFatal (const char *applicationName=0, IOFD fd=IOFD_INVALID, FatalHook hook=0, FatalReturn mainreturn=0, unsigned options=FATAL_DEFAULT) |
static IOFD | handleFatalFd (void) |
static FatalHook | handleFatalHook (void) |
static unsigned | handleFatalOptions (void) |
static FatalReturn | handleFatalReturn (void) |
static void | handleQuit (QuitHook hook=0) |
static QuitHook | handleQuitHook (void) |
static HandlerType | handler (int sig, sigset_t *mask=0) |
static void | ignore (int sig) |
static int | kill (pid_t process, int sig) |
static void | mask (const sigset_t *mask, sigset_t *old=0) |
static const char * | name (int sig) |
static void | pending (sigset_t *mask) |
static bool | pending (int sig) |
static int | queue (pid_t process, int sig, void *value) |
static int | queue (pid_t process, int sig, int value=0) |
static int | queue (int sig, void *value) |
static int | queue (int sig, int value=0) |
static void | quit (int sig, siginfo_t *info, void *x) |
static int | raise (int sig) |
static void | revert (int sig) |
static void | suspend (const sigset_t *mask) |
static int | wait (const sigset_t *mask, siginfo_t *info=0, long msecs=-1) |
static bool | wait (int sig, siginfo_t *info=0, long msecs=-1) |
Static Public Attributes | |
static const int | FATAL_AUTO_EXIT = 256 |
Option to make fatal() exit via quit(). | |
static const int | FATAL_DEFAULT |
Default options to handleFatal(). | |
static const int | FATAL_DUMP_CONTEXT = 128 |
Option to make fataldump() (invoked by fatal()) to dump the machine context (registers etc. | |
static const int | FATAL_DUMP_CORE = 8 |
Option to make fatal() dump a core file before crashing. | |
static const int | FATAL_DUMP_LIBS = 64 |
Option to make fataldump() (invoked by fatal()) to dump the list of currently loaded shared libraries. | |
static const int | FATAL_DUMP_SIG = 16 |
Option to make fataldump() (invoked by fatal()) to dump the signal name (as reported by name()). | |
static const int | FATAL_DUMP_STACK = 32 |
Option to make fataldump() (invoked by fatal()) to dump stack backtrace for the offending code location. | |
static const int | FATAL_ON_INT = 4 |
Option to make SIGINT fatal. | |
static const int | FATAL_ON_QUIT = 2 |
Option to make SIGHUP, SIGTERM and SIGQUIT fatal instead of just quit() signals. | |
static const int | USR1_DUMP_CORE = 1 |
Option that instructs fatal() to call coredump() on SIGUSR1. | |
Static Private Member Functions | |
static const char * | describe (int sig, int code) |
static void | trampoline (int sig) |
Static Private Attributes | |
static const char * | s_applicationName |
static bool | s_crashed |
static IOFD | s_fatalFd |
static FatalHook | s_fatalHook |
static unsigned | s_fatalOptions |
static FatalReturn | s_fatalReturn |
static int | s_inFatal |
static QuitHook | s_quitHook |
static HandlerType | s_trampolines [NSIG] |
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 65 of file Signal.h.
typedef bool(* lat::Signal::FatalHook)(int sig, siginfo_t *info, void *x) |
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(), or it could reuse an internal function in both handlers.
typedef void(* lat::Signal::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.
It must never return. sig is the signal number, or its negative if core was dumped and, as far as can determined, successfully produced.
typedef void(* lat::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. |
typedef bool(* lat::Signal::QuitHook)(int sig, siginfo_t *info, void *x) |
Application clean-up hook invoked before quit() 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.
Referenced by IgQtAppCrashAlertService::hasCrashed(), and IgApplication::run().
Referenced by IgOnCrashService::defaultFatalSignal().
static HandlerType lat::Signal::handle | ( | int | sig, | |
HandlerType | handler, | |||
const sigset_t * | blockMask = 0 | |||
) | [static] |
static void lat::Signal::handleFatal | ( | const char * | applicationName = 0 , |
|
IOFD | fd = IOFD_INVALID , |
|||
FatalHook | hook = 0 , |
|||
FatalReturn | mainreturn = 0 , |
|||
unsigned | options = FATAL_DEFAULT | |||
) | [static] |
Referenced by IgOnCrashService::init(), and VisQueueProcessor::process().
static unsigned lat::Signal::handleFatalOptions | ( | void | ) | [static] |
static FatalReturn lat::Signal::handleFatalReturn | ( | void | ) | [static] |
static HandlerType lat::Signal::handler | ( | int | sig, | |
sigset_t * | mask = 0 | |||
) | [static] |
static const char* lat::Signal::name | ( | int | sig | ) | [static] |
Referenced by IgOnCrashService::defaultFatalSignal().
static int lat::Signal::wait | ( | const sigset_t * | mask, | |
siginfo_t * | info = 0 , |
|||
long | msecs = -1 | |||
) | [static] |
const int lat::Signal::FATAL_AUTO_EXIT = 256 [static] |
const int lat::Signal::FATAL_DEFAULT [static] |
Initial value:
(USR1_DUMP_CORE | FATAL_ON_INT | FATAL_DUMP_CORE | FATAL_DUMP_SIG | FATAL_DUMP_STACK | FATAL_DUMP_LIBS | FATAL_DUMP_CONTEXT | FATAL_AUTO_EXIT)
const int lat::Signal::FATAL_DUMP_CONTEXT = 128 [static] |
const int lat::Signal::FATAL_DUMP_CORE = 8 [static] |
const int lat::Signal::FATAL_DUMP_LIBS = 64 [static] |
const int lat::Signal::FATAL_DUMP_SIG = 16 [static] |
const int lat::Signal::FATAL_DUMP_STACK = 32 [static] |
const int lat::Signal::FATAL_ON_INT = 4 [static] |
const int lat::Signal::FATAL_ON_QUIT = 2 [static] |
const char* lat::Signal::s_applicationName [static, private] |
bool lat::Signal::s_crashed [static, private] |
IOFD lat::Signal::s_fatalFd [static, private] |
FatalHook lat::Signal::s_fatalHook [static, private] |
unsigned lat::Signal::s_fatalOptions [static, private] |
FatalReturn lat::Signal::s_fatalReturn [static, private] |
int lat::Signal::s_inFatal [static, private] |
QuitHook lat::Signal::s_quitHook [static, private] |
HandlerType lat::Signal::s_trampolines[NSIG] [static, private] |
const int lat::Signal::USR1_DUMP_CORE = 1 [static] |
Option that instructs fatal() 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.