From 1d1eedb086d67b1ed113b2165fdb08d0791bfe39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Tue, 18 Apr 2017 14:08:48 +0200 Subject: [PATCH] logger: register shutdown hook for graceful shutdown This will avoid file system corruptions in cases where px4_shutdown_request is used. However it will not help obviously when the battery is pulled directly. --- src/modules/logger/logger.cpp | 14 ++++++++++++++ src/modules/logger/logger.h | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/src/modules/logger/logger.cpp b/src/modules/logger/logger.cpp index d4893d1e08..272f8b9ede 100644 --- a/src/modules/logger/logger.cpp +++ b/src/modules/logger/logger.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -449,6 +450,15 @@ Logger::~Logger() } } +bool Logger::request_stop() +{ + if (logger_ptr) { + logger_ptr->_task_should_exit = true; + } + + return logger_task == -1; +} + int Logger::add_topic(const orb_metadata *topic) { int fd = -1; @@ -782,6 +792,8 @@ void Logger::run() uint32_t total_bytes = 0; #endif /* DBGPRINT */ + px4_register_shutdown_hook(&Logger::request_stop); + // we start logging immediately // the case where we wait with logging until vehicle is armed is handled below if (_log_on_start) { @@ -1087,6 +1099,8 @@ void Logger::run() if (vehicle_command_sub != -1) { orb_unsubscribe(vehicle_command_sub); } + + px4_unregister_shutdown_hook(&Logger::request_stop); } bool Logger::write_message(void *ptr, size_t size) diff --git a/src/modules/logger/logger.h b/src/modules/logger/logger.h index 03651a64af..cd27f05687 100644 --- a/src/modules/logger/logger.h +++ b/src/modules/logger/logger.h @@ -111,6 +111,12 @@ public: static int start(char *const *argv); + /** + * request the logger thread to stop (this method does not block). + * @return true if the logger is stopped, false if (still) running + */ + static bool request_stop(); + static void usage(const char *reason); void status();