diff --git a/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp b/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp index d89296b6a0fec..4177d86ab2e77 100644 --- a/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp +++ b/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp @@ -463,7 +463,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(); @@ -493,6 +497,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 87089427aaa06..a0dc7f20453ee 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 @@ class HAL_Linux : public AP_HAL::HAL { static void exit_signal_handler(int); protected: - bool _should_exit = false; + volatile sig_atomic_t _should_exit = false; }; #if HAL_NUM_CAN_IFACES