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:
Beat Küng
2016-05-09 11:08:45 +02:00
committed by Lorenz Meier
parent d7f0808316
commit cfa491467e
2 changed files with 11 additions and 8 deletions
+10 -7
View File
@@ -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;