mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-07 05:20:34 +08:00
logger: fix 'logger stop' when nothing has been logged yet
when executing 'logger stop' and the logger did not log yet, _running was false, so log_writer thread would never exit.
This commit is contained in:
@@ -182,6 +182,7 @@ void LogWriter::run()
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&_mtx);
|
||||
written = 0;
|
||||
|
||||
if (available > 0) {
|
||||
perf_begin(perf_write);
|
||||
@@ -211,20 +212,22 @@ void LogWriter::run()
|
||||
_total_written += written;
|
||||
}
|
||||
|
||||
if (_running && !_should_run && written == static_cast<int>(available) && !is_part) {
|
||||
if (!_should_run && written == static_cast<int>(available) && !is_part) {
|
||||
// Stop only when all data written
|
||||
_running = false;
|
||||
_head = 0;
|
||||
_count = 0;
|
||||
|
||||
int res = ::close(_fd);
|
||||
_fd = -1;
|
||||
if (_fd >= 0) {
|
||||
int res = ::close(_fd);
|
||||
_fd = -1;
|
||||
|
||||
if (res) {
|
||||
PX4_WARN("error closing log file");
|
||||
if (res) {
|
||||
PX4_WARN("error closing log file");
|
||||
|
||||
} else {
|
||||
PX4_WARN("closed logfile: %s, bytes written: %zu", _filename, _total_written);
|
||||
} else {
|
||||
PX4_WARN("closed logfile: %s, bytes written: %zu", _filename, _total_written);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -117,7 +117,7 @@ private:
|
||||
static constexpr size_t _min_write_chunk = 4096;
|
||||
|
||||
char _filename[64];
|
||||
int _fd;
|
||||
int _fd = -1;
|
||||
uint8_t *_buffer = nullptr;
|
||||
const size_t _buffer_size;
|
||||
size_t _head = 0; ///< next position to write to
|
||||
|
||||
Reference in New Issue
Block a user