iceoryx_hoofs 2.0.5
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
iox::posix::SignalGuard Class Reference

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 <iceoryx_hoofs/posix_wrapper/signal_handler.hpp>

Public Member Functions

 SignalGuard (SignalGuard &&rhs) noexcept
 
 SignalGuard (const SignalGuard &)=delete
 
SignalGuardoperator= (const SignalGuard &rhs)=delete
 
SignalGuardoperator= (SignalGuard &&rhs)=delete
 

Friends

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

Detailed Description

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
friend SignalGuard registerSignalHandler(const Signal, const SignalHandlerCallback_t) noexcept
Register a callback for a specific posix signal (SIG***).

Friends And Related Symbol Documentation

◆ registerSignalHandler

SignalGuard registerSignalHandler ( const Signal  ,
const SignalHandlerCallback_t   
)
friend

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
[in]Signalthe signal to which the callback should be attached
[in]callbackthe callback which should be called when the signal is raised.
Returns
SignalGuard, when it goes out of scope the previous signal action is restored.

The documentation for this class was generated from the following file: