logger: unlock the mutex for fsync & call fsync only when backend is running

- fsync can be a long blocking operation, so we need to make sure the main
  logger thread does not block during this time, when it tries to aquire
  the mutex
- fixes calling fsync on an invalid file descriptor
This commit is contained in:
Beat Küng
2018-11-06 13:24:48 +01:00
committed by Lorenz Meier
parent 7caf9803ed
commit df559f3042

View File

@@ -257,8 +257,10 @@ void LogWriterFile::run()
buffer.close_file();
}
} else if (call_fsync) {
} else if (call_fsync && buffer._should_run) {
pthread_mutex_unlock(&_mtx);
buffer.fsync();
pthread_mutex_lock(&_mtx);
} else if (available == 0 && !buffer._should_run) {
buffer.close_file();