From b971b61eed8192a7dc91110453dee8677ef10112 Mon Sep 17 00:00:00 2001 From: Javier Arribas Date: Sat, 30 Sep 2023 14:48:04 +0200 Subject: [PATCH] Adding standard UNIX/POSIX signals listener. GNSS-SDR now can be safely stopped using CTL+C --- src/core/receiver/control_thread.cc | 40 +++++++++++++++++++++++++++++ src/core/receiver/control_thread.h | 7 +++++ 2 files changed, 47 insertions(+) diff --git a/src/core/receiver/control_thread.cc b/src/core/receiver/control_thread.cc index 18da0e6b0..1816e4d38 100644 --- a/src/core/receiver/control_thread.cc +++ b/src/core/receiver/control_thread.cc @@ -78,9 +78,49 @@ namespace wht = std; extern Concurrent_Map global_gps_acq_assist_map; extern Concurrent_Queue global_gps_acq_assist_queue; +ControlThread* ControlThread::me=nullptr; + + +/** + * \brief Callback function for handling signals. + * \param sig identifier of signal + */ +void ControlThread::handle_signal(int sig) +{ + if (sig == SIGINT) + { + std::cout << "Stopping GNSS-SDR via SIGINT...\n"; + + ControlThread::me->control_queue_->push(pmt::make_any(command_event_make(200, 0))); + ControlThread::me->stop_ = true; + + /* Reset signal handling to default behavior */ + signal(SIGINT, SIG_DFL); + } + else if (sig == SIGHUP) + { + + std::cout << "Debug: received SIGHUP signal\n"; + //std::cout << "Debug: reloading daemon config file ...\n"; + //todo + } + else if (sig == SIGCHLD) + { + std::cout << "Debug: received SIGCHLD signal\n"; + //todo + } +} + ControlThread::ControlThread() { + + ControlThread::me=this; + + /* the class will handle two signals */ + signal(SIGINT, ControlThread::handle_signal); + signal(SIGHUP, ControlThread::handle_signal); + if (FLAGS_c == "-") { configuration_ = std::make_shared(FLAGS_config_file); diff --git a/src/core/receiver/control_thread.h b/src/core/receiver/control_thread.h index 12f6fbc49..37fca1421 100644 --- a/src/core/receiver/control_thread.h +++ b/src/core/receiver/control_thread.h @@ -37,6 +37,7 @@ #include // for std::type_info, typeid #include // for pair #include // for vector +#include #ifdef ENABLE_FPGA #include // for boost::thread @@ -54,6 +55,7 @@ class ConfigurationInterface; class GNSSFlowgraph; class Gnss_Satellite; + /*! * \brief This class represents the main thread of the application, so the name is ControlThread. * This is the GNSS Receiver Control Plane: it connects the flowgraph, starts running it, @@ -63,6 +65,8 @@ class Gnss_Satellite; class ControlThread { public: + + static ControlThread* me; /*! * \brief Default constructor */ @@ -122,6 +126,9 @@ public: } private: + + static void handle_signal(int sig); + void init(); void apply_action(unsigned int what);