diff --git a/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp b/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp index 4b2cd90e28..a0be63c44a 100644 --- a/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp +++ b/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp @@ -467,7 +467,11 @@ void HAL_Linux::run(int argc, char* const argv[], Callbacks* callbacks) const } } - setup_signal_handlers(); + // NOTE: signal handlers are only set before the main loop, so + // that if anything before the loops hangs, the default signals + // can still stop the process proprely, although without proper + // teardown. + // This isn't perfect, but still prevents an unkillable process. scheduler->init(); gpio->init(); @@ -497,6 +501,8 @@ void HAL_Linux::run(int argc, char* const argv[], Callbacks* callbacks) const AP_Module::call_hook_setup_complete(); #endif + setup_signal_handlers(); + while (!_should_exit) { callbacks->loop(); } diff --git a/libraries/AP_HAL_Linux/HAL_Linux_Class.h b/libraries/AP_HAL_Linux/HAL_Linux_Class.h index 87089427aa..a0dc7f2045 100644 --- a/libraries/AP_HAL_Linux/HAL_Linux_Class.h +++ b/libraries/AP_HAL_Linux/HAL_Linux_Class.h @@ -2,6 +2,8 @@ #include +#include + class HAL_Linux : public AP_HAL::HAL { public: HAL_Linux(); @@ -12,7 +14,7 @@ public: static void exit_signal_handler(int); protected: - bool _should_exit = false; + volatile sig_atomic_t _should_exit = false; }; #if HAL_NUM_CAN_IFACES