From ebafa5698d54663a5b66eb99db82d4a1d21b6fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 14 Aug 2017 13:25:34 +0200 Subject: [PATCH] log_writer_file: register hardfault handler before opening the log file hardfault_store_filename() opens and closes a file descriptor, so if we do it before opening the log file, we need one file descriptor less --- src/modules/logger/log_writer_file.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/modules/logger/log_writer_file.cpp b/src/modules/logger/log_writer_file.cpp index cbcb780b7a..05993a18a9 100644 --- a/src/modules/logger/log_writer_file.cpp +++ b/src/modules/logger/log_writer_file.cpp @@ -84,6 +84,16 @@ LogWriterFile::~LogWriterFile() void LogWriterFile::start_log(const char *filename) { + // register the current file with the hardfault handler: if the system crashes, + // the hardfault handler will append the crash log to that file on the next reboot. + // Note that we don't deregister it when closing the log, so that crashes after disarming + // are appended as well (the same holds for crashes before arming, which can be a bit misleading) + int ret = hardfault_store_filename(filename); + + if (ret) { + PX4_ERR("Failed to register ULog file to the hardfault handler (%i)", ret); + } + _fd = ::open(filename, O_CREAT | O_WRONLY, PX4_O_MODE_666); if (_fd < 0) { @@ -104,17 +114,6 @@ void LogWriterFile::start_log(const char *filename) } } - // register the current file with the hardfault handler: if the system crashes, - // the hardfault handler will append the crash log to that file on the next reboot. - // Note that we don't deregister it when closing the log, so that crashes after disarming - // are appended as well (the same holds for crashes before arming, which can be a bit misleading) - int ret = hardfault_store_filename(filename); - - if (ret) { - PX4_ERR("Failed to register ULog file to the hardfault handler (%i)", ret); - } - - PX4_INFO("Opened log file: %s", filename); _should_run = true; _running = true;