Skip to content

iox::posix::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. More...

#include <signal_handler.hpp>

Public Functions🔗

Name
SignalGuard(SignalGuard && rhs)
SignalGuard(const SignalGuard & )
~SignalGuard()
SignalGuard & operator=(const SignalGuard & rhs)
SignalGuard & operator=(SignalGuard && rhs)

Friends🔗

Name
SignalGuard registerSignalHandler(const Signal, const SignalHandlerCallback_t)
Register a callback for a specific posix signal (SIG***).

Detailed Description🔗

class iox::posix::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 Documentation🔗

function SignalGuard🔗

SignalGuard(
    SignalGuard && rhs
)

function SignalGuard🔗

SignalGuard(
    const SignalGuard & 
)

function ~SignalGuard🔗

~SignalGuard()

function operator=🔗

SignalGuard & operator=(
    const SignalGuard & rhs
)

function operator=🔗

SignalGuard & operator=(
    SignalGuard && rhs
)

Friends🔗

friend registerSignalHandler🔗

friend SignalGuard registerSignalHandler(
    const Signal,
    const SignalHandlerCallback_t
);

Register a callback for a specific posix signal (SIG***).

Parameters:

  • Signal the signal to which the callback should be attached
  • callback the callback which should be called when the signal is raised.

Return: SignalGuard, when it goes out of scope the previous signal action is restored.

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.


Updated on 31 May 2022 at 15:29:15 CEST