Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow proper shutdown in Linux #25746

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion libraries/AP_HAL_Linux/HAL_Linux_Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion libraries/AP_HAL_Linux/HAL_Linux_Class.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <AP_HAL/AP_HAL.h>

#include <signal.h>

class HAL_Linux : public AP_HAL::HAL {
public:
HAL_Linux();
Expand All @@ -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
Expand Down