diff --git a/os/log.c b/os/log.c index 89a1214de..ae07ec3ce 100644 --- a/os/log.c +++ b/os/log.c @@ -230,6 +230,12 @@ LogFilePrep(const char *fname, const char *backup, const char *idstring) } #pragma GCC diagnostic pop +static inline void doLogSync(void) { +#ifndef WIN32 + fsync(logFileFd); +#endif +} + /* * LogInit is called to start logging to a file. It is also called (with * NULL arguments) when logging to a file is not wanted. It must always be @@ -272,9 +278,7 @@ LogInit(const char *fname, const char *backup) /* Flush saved log information. */ if (saveBuffer && bufferSize > 0) { write(logFileFd, saveBuffer, bufferPos); -#ifndef WIN32 - fsync(logFileFd); -#endif + doLogSync(); } } @@ -599,10 +603,8 @@ LogSWrite(int verb, const char *buf, size_t len, Bool end_line) if (verb < 0 || logFileVerbosity >= verb) { if (inSignalContext && logFileFd >= 0) { ret = write(logFileFd, buf, len); -#ifndef WIN32 if (logSync) - fsync(logFileFd); -#endif + doLogSync(); } else if (!inSignalContext && logFileFd != -1) { if (newline) { @@ -616,10 +618,8 @@ LogSWrite(int verb, const char *buf, size_t len, Bool end_line) } newline = end_line; write(logFileFd, buf, len); -#ifndef WIN32 if (logSync) - fsync(logFileFd); -#endif + doLogSync(); } else if (!inSignalContext && needBuffer) { if (len > bufferUnused) {