AP_Logger: file content: log only file name if directory won't fit

This commit is contained in:
Iampete1 2021-11-16 17:20:04 +00:00 committed by Andrew Tridgell
parent 09dfcdb574
commit 7b0f059968
2 changed files with 9 additions and 1 deletions

View File

@ -1416,6 +1416,13 @@ void AP_Logger::log_file_content(const char *filename)
}
strncpy(tmp_filename, filename, len);
file->filename = tmp_filename;
// Remove directory if whole file name will not fit
const char * name = strrchr(file->filename, '/');
if ((len-1 > sizeof(file->log_filename)) && (name != nullptr)) {
strncpy_noterm(file->log_filename, name+1, sizeof(file->log_filename));
} else {
strncpy_noterm(file->log_filename, file->filename, sizeof(file->log_filename));
}
if (file_content.head == nullptr) {
file_content.tail = file_content.head = file;
file_content.fd = -1;
@ -1461,7 +1468,7 @@ void AP_Logger::file_content_update(void)
struct log_File pkt {
LOG_PACKET_HEADER_INIT(LOG_FILE_MSG),
};
strncpy_noterm(pkt.filename, file->filename, sizeof(pkt.filename));
memcpy(pkt.filename, file->log_filename, sizeof(pkt.filename));
const auto length = AP::FS().read(file_content.fd, pkt.data, sizeof(pkt.data));
if (length <= 0) {
AP::FS().close(file_content.fd);

View File

@ -561,6 +561,7 @@ private:
struct file_list {
struct file_list *next;
const char *filename;
char log_filename[16];
};
struct {
struct file_list *head, *tail;