Skip to content
Snippets Groups Projects
Commit 58b2639f authored by René Fritze's avatar René Fritze
Browse files

documentation and generalisation of signals

parent 32725d2a
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,8 @@
namespace Stuff {
namespace Signals {
//! reset given signal to default handler
void resetSignal(int signal)
{
struct sigaction new_action;
......@@ -16,6 +18,7 @@ void resetSignal(int signal)
sigaction(signal, &new_action, NULL);
}
//! example signal handler
void handleInterrupt(int signal)
{
Logger().Info() << "forcefully terminated at " << Logging::TimeString() << std::endl;
......@@ -25,16 +28,20 @@ void handleInterrupt(int signal)
kill(getpid(), signal);
}
void installSignalHandlers()
//! type of handler functions
typedef void handler_type(int);
//! calling this from your main() will install handler as callback when signal is received
void installSignalHandler(int signal = SIGINT, handler_type handler = handleInterrupt)
{
struct sigaction new_action;
/* Set up the structure to specify the new action. */
new_action.sa_handler = handleInterrupt;
new_action.sa_handler = handler;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = 0;
sigaction(SIGINT, &new_action, NULL);
sigaction(signal, &new_action, NULL);
}
} // end namespace signals
} // end namepsace stuff
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment