enable line buffering on all log files
Costa Tsaousis committed
May 8, 2016 at 03:45 UTC
8f58269316f87f8b09f88177f652733923b11114
2 files changed
+12
-2
src/daemon.c
+10
@@ -208,6 +208,8 @@ int become_daemon(int dont_fork, int close_all_files, const char *user, const ch
208
*access_fd = -1;
209
return -1;
210
}
211
+ if(setvbuf(*access_fp, NULL, _IOLBF, 0) != 0)
212
+ error("Cannot set line buffering on access.log");
213
}
214
}
215
@@ -301,6 +303,10 @@ int become_daemon(int dont_fork, int close_all_files, const char *user, const ch
303
dup2(output_fd, STDOUT_FILENO);
304
close(output_fd);
305
}
306
+
307
+ if(setvbuf(stdout, NULL, _IOLBF, 0) != 0)
308
+ error("Cannot set line buffering on debug.log");
309
+
310
output_fd = -1;
311
}
312
else dup2(dev_null, STDOUT_FILENO);
@@ -310,6 +316,10 @@ int become_daemon(int dont_fork, int close_all_files, const char *user, const ch
316
dup2(error_fd, STDERR_FILENO);
317
close(error_fd);
318
}
319
+
320
+ if(setvbuf(stderr, NULL, _IOLBF, 0) != 0)
321
+ error("Cannot set line buffering on error.log");
322
+
323
error_fd = -1;
324
}
325
else dup2(dev_null, STDERR_FILENO);
src/log.c
+2
-2
@@ -131,7 +131,7 @@ void debug_int( const char *file, const char *function, const unsigned long line
131
vfprintf( stdout, fmt, args );
132
va_end( args );
133
fprintf(stdout, "\n");
134
- fflush( stdout );
134
+ // fflush( stdout );
135
136
if(output_log_syslog) {
137
va_start( args, fmt );
@@ -229,7 +229,7 @@ void log_access( const char *fmt, ... )
229
vfprintf( stdaccess, fmt, args );
230
va_end( args );
231
fprintf( stdaccess, "\n");
232
- fflush( stdaccess );
232
+ // fflush( stdaccess );
233
}
234
235
if(access_log_syslog) {