(!1682) 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
							
								
									3a6bcb854e
								
							
						
					
					
						commit
						a61a5e0eb7
					
				
							
								
								
									
										18
									
								
								os/log.c
								
								
								
								
							
							
						
						
									
										18
									
								
								os/log.c
								
								
								
								
							|  | @ -200,6 +200,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 | ||||
|  | @ -242,9 +248,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(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -569,10 +573,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) { | ||||
|  | @ -586,10 +588,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) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue