mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-22 16:27:35 +08:00
hardfault_log: move hardfault_store_ulog_filename to logger module
This commit is contained in:
@@ -104,18 +104,16 @@ void LogWriterFile::start_log(const char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __PX4_NUTTX
|
||||
// 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_ulog_filename(filename);
|
||||
int ret = hardfault_store_filename(filename);
|
||||
|
||||
if (ret) {
|
||||
PX4_ERR("Failed to register ULog file to the hardfault handler (%i)", ret);
|
||||
}
|
||||
|
||||
#endif /* __PX4_NUTTX */
|
||||
|
||||
PX4_INFO("Opened log file: %s", filename);
|
||||
_should_run = true;
|
||||
@@ -128,6 +126,38 @@ void LogWriterFile::start_log(const char *filename)
|
||||
notify();
|
||||
}
|
||||
|
||||
int LogWriterFile::hardfault_store_filename(const char *log_file)
|
||||
{
|
||||
#ifdef __PX4_NUTTX
|
||||
int fd = open(HARDFAULT_ULOG_PATH, O_TRUNC | O_WRONLY | O_CREAT);
|
||||
|
||||
if (fd < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
int n = strlen(log_file);
|
||||
|
||||
if (n >= HARDFAULT_MAX_ULOG_FILE_LEN) {
|
||||
PX4_ERR("ULog file name too long (%s, %i>=%i)\n", log_file, n, HARDFAULT_MAX_ULOG_FILE_LEN);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (n + 1 != ::write(fd, log_file, n + 1)) {
|
||||
close(fd);
|
||||
return -errno;
|
||||
}
|
||||
|
||||
int ret = close(fd);
|
||||
|
||||
if (ret != 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
#endif /* __PX4_NUTTX */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LogWriterFile::stop_log()
|
||||
{
|
||||
_should_run = false;
|
||||
|
||||
Reference in New Issue
Block a user