mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-06 06:43:21 +08:00
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:
@@ -84,6 +84,16 @@ LogWriterFile::~LogWriterFile()
|
|||||||
|
|
||||||
void LogWriterFile::start_log(const char *filename)
|
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);
|
_fd = ::open(filename, O_CREAT | O_WRONLY, PX4_O_MODE_666);
|
||||||
|
|
||||||
if (_fd < 0) {
|
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);
|
PX4_INFO("Opened log file: %s", filename);
|
||||||
_should_run = true;
|
_should_run = true;
|
||||||
_running = true;
|
_running = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user