E-MailRelay
|
A static interface for registering cleanup functions that are called when the process terminates abnormally. More...
#include <gcleanup.h>
Classes | |
struct | Arg |
Opaque leaky string pointer wrapper created by G::Cleanup::arg(). More... | |
struct | Block |
A RAII class to temporarily block signal delivery. More... | |
Public Types | |
using | Fn = bool(*)(const Arg &) GDEF_FSIG_NOEXCEPT |
Static Public Member Functions | |
static void | init () |
An optional early-initialisation function. May be called more than once. More... | |
static void | add (Fn, Arg arg) |
Adds the given handler to the list of handlers that are to be called when the process terminates abnormally. More... | |
static void | atexit (bool active=true) |
Ensures that the cleanup functions are also called via atexit(), in addition to abnormal-termination signals. More... | |
static void | block () noexcept |
Temporarily blocks signals until release()d. More... | |
static void | release () noexcept |
Releases block()ed signals. More... | |
static Arg | arg (const char *) |
Duplicates a c-string for add(). More... | |
static Arg | arg (const std::string &) |
Duplicates a string for add(). More... | |
static Arg | arg (const Path &) |
Duplicates a path for add(). More... | |
static Arg | arg (std::nullptr_t) |
Duplicates an empty string for add(). More... | |
A static interface for registering cleanup functions that are called when the process terminates abnormally.
On unix this relates to signals like SIGTERM, SIGINT etc.
Definition at line 40 of file gcleanup.h.
using G::Cleanup::Fn = bool (*)(const Arg &) GDEF_FSIG_NOEXCEPT |
Definition at line 63 of file gcleanup.h.
|
static |
Adds the given handler to the list of handlers that are to be called when the process terminates abnormally.
In principle the handler function should be fully reentrant and signal-safe.
The 'arg' value should come from arg(). The Arg object contains a copy of the data passed to it. It uses memory allocated on the heap which is never freed because it has to remain valid even as the process is terminating.
Once the handler returns true it is removed from the list of handlers; if it returns false then it may be retried.
Definition at line 94 of file gcleanup_unix.cpp.
|
static |
Duplicates a c-string for add().
The duped pointer will be passed to the handler.
Definition at line 117 of file gcleanup_unix.cpp.
|
static |
Duplicates a path for add().
The path's string pointer will be passed to the handler.
Definition at line 130 of file gcleanup_unix.cpp.
|
static |
Duplicates a string for add().
The duplicate's data() pointer will be passed to the handler.
Definition at line 124 of file gcleanup_unix.cpp.
|
static |
Duplicates an empty string for add().
Definition at line 137 of file gcleanup_unix.cpp.
|
static |
Ensures that the cleanup functions are also called via atexit(), in addition to abnormal-termination signals.
This can be useful when ancient third-party library code (eg. Xlib) might call exit(), but be careful to disable these exit handlers before normal termination by calling atexit(false).
Definition at line 100 of file gcleanup_unix.cpp.
|
staticnoexcept |
Temporarily blocks signals until release()d.
This should be used before creating threads so that only the main thread does signal handling.
Definition at line 106 of file gcleanup_unix.cpp.
|
static |
An optional early-initialisation function. May be called more than once.
Definition at line 89 of file gcleanup_unix.cpp.
|
staticnoexcept |
Releases block()ed signals.
Definition at line 111 of file gcleanup_unix.cpp.