Class SignalGuard
Defined in File signal_handler.hpp
Class Documentation
-
class SignalGuard
The SignalGuard is a class returned by registerSignalHandler. When it goes out of scope it restores the previous signal action. Typical use case: One would like to override the signal action in main() or some C posix makes it necessary to override the standard signal action before and after the call.
- Attention
NEVER USE THIS CLASS AS A MEMBER VARIABLE! A class which should be used only in method/function scopes.
{ auto signalGuard = registerSignalHandler(Signal::BUS, printErrorMessage); my_c_call_which_can_cause_SIGBUS(); } // here we are out of scope and the signal action for Signal::BUS is restored
Public Functions
-
SignalGuard(SignalGuard &&rhs) noexcept
-
SignalGuard(const SignalGuard&) = delete
-
~SignalGuard() noexcept
-
SignalGuard &operator=(const SignalGuard &rhs) = delete
-
SignalGuard &operator=(SignalGuard &&rhs) = delete
Friends
-
friend SignalGuard registerSignalHandler(const Signal, const SignalHandlerCallback_t) noexcept
Register a callback for a specific posix signal (SIG***).
- Attention
if a signal callback was already registered for the provided signal with registerSignalHandler or with sigaction() or signal(), the signal callback is overridden until the SignalGuard goes out of scope and restores the previous callback. If you override the callbacks multiple times and the created SignalGuards goes out of scope in a different order then the callback is restored which was active when the last SignalGuard which is going out of scope was created.
- Parameters:
Signal – [in] the signal to which the callback should be attached
callback – [in] the callback which should be called when the signal is raised.
- Returns:
SignalGuard, when it goes out of scope the previous signal action is restored.