From be985a652b421a7f752b3381e1df0f29e37c582c Mon Sep 17 00:00:00 2001 From: dhood Date: Mon, 7 Aug 2017 16:19:11 -0700 Subject: [PATCH] Restore old signal handler on shutdown --- rclcpp/src/rclcpp/utilities.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rclcpp/src/rclcpp/utilities.cpp b/rclcpp/src/rclcpp/utilities.cpp index 18a6d38..4d20c33 100644 --- a/rclcpp/src/rclcpp/utilities.cpp +++ b/rclcpp/src/rclcpp/utilities.cpp @@ -167,8 +167,16 @@ rclcpp::utilities::init(int argc, char * argv[]) action.sa_sigaction = ::signal_handler; action.sa_flags = SA_SIGINFO; ::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 ::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 }