Restore old signal handler on shutdown

This commit is contained in:
dhood 2017-08-07 16:19:11 -07:00
parent c15db0b675
commit be985a652b

View file

@ -167,8 +167,16 @@ rclcpp::utilities::init(int argc, char * argv[])
action.sa_sigaction = ::signal_handler; action.sa_sigaction = ::signal_handler;
action.sa_flags = SA_SIGINFO; action.sa_flags = SA_SIGINFO;
::old_action = set_sigaction(SIGINT, action); ::old_action = set_sigaction(SIGINT, action);
// Register an on_shutdown hook to restore the old action.
rclcpp::utilities::on_shutdown([]() {
set_sigaction(SIGINT, ::old_action);
});
#else #else
::old_signal_handler = set_signal_handler(SIGINT, ::signal_handler); ::old_signal_handler = set_signal_handler(SIGINT, ::signal_handler);
// Register an on_shutdown hook to restore the old signal handler.
rclcpp::utilities::on_shutdown([]() {
set_signal_handler(SIGINT, ::old_signal_handler);
});
#endif #endif
} }