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.
This commit is contained in:
Beat Küng
2017-04-18 14:08:48 +02:00
committed by Lorenz Meier
parent 0165633bf3
commit 1d1eedb086
2 changed files with 20 additions and 0 deletions
+14
View File
@@ -58,6 +58,7 @@
#include <px4_log.h>
#include <px4_posix.h>
#include <px4_sem.h>
#include <px4_shutdown.h>
#include <px4_tasks.h>
#include <systemlib/mavlink_log.h>
#include <replay/definitions.hpp>
@@ -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)