Patchwork [5/9] petitboot: Flush log stream on write

login
register
mail settings
Submitter Geoff Levand
Date Jan. 22, 2009, 12:26 a.m.
Message ID <20090122002653.545966402@am.sony.com>
Download mbox | patch
Permalink /patch/19742/
State Accepted
Delegated to: Jeremy Kerr
Headers show

Comments

Geoff Levand - Jan. 22, 2009, 12:26 a.m.
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>
---
 lib/log.c |   10 ++++++++++
 lib/log.h |    1 +
 2 files changed, 11 insertions(+)

Patch

--- a/lib/log.c
+++ b/lib/log.c
@@ -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;
+}
--- a/lib/log.h
+++ b/lib/log.h
@@ -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 */