Browse Source

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.
sbg
Beat Küng 9 years ago committed by Lorenz Meier
parent
commit
cfa491467e
  1. 17
      src/modules/logger/log_writer.cpp
  2. 2
      src/modules/logger/log_writer.h

17
src/modules/logger/log_writer.cpp

@ -182,6 +182,7 @@ void LogWriter::run() @@ -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() @@ -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;

2
src/modules/logger/log_writer.h

@ -117,7 +117,7 @@ private: @@ -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

Loading…
Cancel
Save