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
This commit is contained in:
Beat Küng 2017-08-14 13:25:34 +02:00
parent 9e01842c6a
commit ebafa5698d

View File

@ -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;