os: log: consolidate OS specific fsync() call into helper
Instead of having lots of #ifdef's, consolidating the conditionally compiled fsync() call into a tiny inline helper. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
917d8dc207
commit
7d3e56722c
18
os/log.c
18
os/log.c
|
@ -199,6 +199,12 @@ LogFilePrep(const char *fname, const char *backup, const char *idstring)
|
||||||
}
|
}
|
||||||
#pragma GCC diagnostic pop
|
#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
|
* 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
|
* NULL arguments) when logging to a file is not wanted. It must always be
|
||||||
|
@ -241,9 +247,7 @@ LogInit(const char *fname, const char *backup)
|
||||||
/* Flush saved log information. */
|
/* Flush saved log information. */
|
||||||
if (saveBuffer && bufferSize > 0) {
|
if (saveBuffer && bufferSize > 0) {
|
||||||
write(logFileFd, saveBuffer, bufferPos);
|
write(logFileFd, saveBuffer, bufferPos);
|
||||||
#ifndef WIN32
|
doLogSync();
|
||||||
fsync(logFileFd);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,10 +560,8 @@ LogSWrite(int verb, const char *buf, size_t len, Bool end_line)
|
||||||
if (verb < 0 || logFileVerbosity >= verb) {
|
if (verb < 0 || logFileVerbosity >= verb) {
|
||||||
if (inSignalContext && logFileFd >= 0) {
|
if (inSignalContext && logFileFd >= 0) {
|
||||||
ret = write(logFileFd, buf, len);
|
ret = write(logFileFd, buf, len);
|
||||||
#ifndef WIN32
|
|
||||||
if (logSync)
|
if (logSync)
|
||||||
fsync(logFileFd);
|
doLogSync();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (!inSignalContext && logFileFd != -1) {
|
else if (!inSignalContext && logFileFd != -1) {
|
||||||
if (newline) {
|
if (newline) {
|
||||||
|
@ -573,10 +575,8 @@ LogSWrite(int verb, const char *buf, size_t len, Bool end_line)
|
||||||
}
|
}
|
||||||
newline = end_line;
|
newline = end_line;
|
||||||
write(logFileFd, buf, len);
|
write(logFileFd, buf, len);
|
||||||
#ifndef WIN32
|
|
||||||
if (logSync)
|
if (logSync)
|
||||||
fsync(logFileFd);
|
doLogSync();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (!inSignalContext && needBuffer) {
|
else if (!inSignalContext && needBuffer) {
|
||||||
if (len > bufferUnused) {
|
if (len > bufferUnused) {
|
||||||
|
|
Loading…
Reference in New Issue