(!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
							
								
									3d4c4d4e86
								
							
						
					
					
						commit
						c6fb4baea9
					
				
							
								
								
									
										18
									
								
								os/log.c
								
								
								
								
							
							
						
						
									
										18
									
								
								os/log.c
								
								
								
								
							|  | @ -198,6 +198,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 | ||||||
|  | @ -240,9 +246,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 |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -554,10 +558,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) { | ||||||
|  | @ -571,10 +573,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