]> git.ozlabs.org Git - petitboot/commitdiff
Flush log stream on write
authorGeoff Levand <geoffrey.levand@am.sony.com>
Thu, 22 Jan 2009 00:26:58 +0000 (16:26 -0800)
committerJeremy Kerr <jk@ozlabs.org>
Sun, 1 Feb 2009 00:53:55 +0000 (11:53 +1100)
Flush the pb_log stream when the stream is changed, and add an
option to flush the pb_log stream on every write.  Useful while
debugging.

Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
lib/log/log.c
lib/log/log.h

index e006fd0b1495c34867648ae58ff047113de751a6..41b44cc10ff9e02aa227d7ae0e4ccd3592052265 100644 (file)
@@ -4,6 +4,7 @@
 #include "log.h"
 
 static FILE *logf;
+static int always_flush;
 
 void pb_log(const char *fmt, ...)
 {
@@ -15,9 +16,18 @@ void pb_log(const char *fmt, ...)
        va_start(ap, fmt);
        vfprintf(stream, fmt, ap);
        va_end(ap);
+
+       if (always_flush)
+               fflush(stream);
 }
 
 void pb_log_set_stream(FILE *stream)
 {
+       fflush(logf ? logf : stdout);
        logf = stream;
 }
+
+void pb_log_always_flush(int state)
+{
+       always_flush = state;
+}
index 3e92555a12c62a104694860faa3fa9419c1bfec4..813a19e293773fd9f72ad5c8092a7498d9b65a54 100644 (file)
@@ -5,5 +5,6 @@
 
 void pb_log(const char *fmt, ...);
 void pb_log_set_stream(FILE *stream);
+void pb_log_always_flush(int state);
 
 #endif /* _LOG_H */