From 38a0fe31aa4c8e2f9687c28dcc2a9718499da72f Mon Sep 17 00:00:00 2001 From: Jari Nippula Date: Fri, 27 Dec 2024 12:03:28 +0200 Subject: [PATCH] logger: fix file open issue if crypto algorithm is disabled Create empty file even if crypto key is not stored into the beginning of the log file to allow file logger to always append log data into existing file. --- src/modules/logger/log_writer_file.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/logger/log_writer_file.cpp b/src/modules/logger/log_writer_file.cpp index 14a2ad01368f..2a3076e3b75c 100644 --- a/src/modules/logger/log_writer_file.cpp +++ b/src/modules/logger/log_writer_file.cpp @@ -92,6 +92,16 @@ bool LogWriterFile::init_logfile_encryption(const char *filename) { if (_algorithm == CRYPTO_NONE) { _min_blocksize = 1; + + // No encryption, just create empty log file + int fd = ::open((const char *)filename, O_CREAT | O_WRONLY | O_DIRECT | O_SYNC, PX4_O_MODE_666); + + if (fd < 0) { + PX4_ERR("Can't open log file, errno: %d", errno); + return false; + } + + ::close(fd); return true; }