From 9132e7a42ad53fcf47bd43336bf633c36610bf1a Mon Sep 17 00:00:00 2001 From: Marcelo Aquino Date: Fri, 12 Aug 2016 12:42:49 -0300 Subject: [PATCH] Exit immediately when receiving a signal --- core/MyMainLinux.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/MyMainLinux.cpp b/core/MyMainLinux.cpp index 5ecab96..5798cec 100644 --- a/core/MyMainLinux.cpp +++ b/core/MyMainLinux.cpp @@ -1,18 +1,15 @@ // Initialize library and handle sketch functions like we want to #include -#include +#include +#include #include "MySensorsCore.h" -volatile static int running = 1; - /* * handler for SIGINT signal */ void handle_sigint(int sig) { - running = 0; - if (sig == SIGINT) { std::cout << "Received SIGINT\n" << std::endl; } else if (sig == SIGTERM) { @@ -22,6 +19,8 @@ void handle_sigint(int sig) #ifdef MY_RF24_IRQ_PIN detachInterrupt(MY_RF24_IRQ_PIN); #endif + + exit(0); } int main(void) { @@ -31,7 +30,7 @@ int main(void) { _begin(); // Startup MySensors library - while (running) { + for (;;) { _process(); // Process incoming data if (loop) loop(); // Call sketch loop }