summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-06-24 01:31:08 +0200
committerRichard Braun <rbraun@sceen.net>2017-06-24 01:31:08 +0200
commita2729aef568285daff96ffc5719caf8e26043ca9 (patch)
tree20eb5a30bde47a38c16cf08cda9f47bad7746816
parentaeea74bc5438895f09329ef1a3a006f251ae25ce (diff)
kern/log: force log messages to fit in a single line
-rw-r--r--kern/log.c9
-rw-r--r--kern/log.h6
2 files changed, 14 insertions, 1 deletions
diff --git a/kern/log.c b/kern/log.c
index adba7d33..96be1528 100644
--- a/kern/log.c
+++ b/kern/log.c
@@ -22,6 +22,7 @@
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
+#include <string.h>
#include <kern/cbuf.h>
#include <kern/init.h>
@@ -457,6 +458,7 @@ log_vmsg(unsigned int level, const char *format, va_list ap)
unsigned long flags;
int nr_chars;
size_t size;
+ char *ptr;
log_record_init_produce(&record, level);
nr_chars = vsnprintf(record.buffer, sizeof(record.buffer), format, ap);
@@ -466,6 +468,13 @@ log_vmsg(unsigned int level, const char *format, va_list ap)
goto out;
}
+ ptr = strchr(record.buffer, '\n');
+
+ if (ptr != NULL) {
+ *ptr = '\0';
+ nr_chars = ptr - record.buffer;
+ }
+
assert(nr_chars >= 0);
size = offsetof(struct log_record, buffer) + nr_chars + 1;
diff --git a/kern/log.h b/kern/log.h
index a306ba36..003e99b2 100644
--- a/kern/log.h
+++ b/kern/log.h
@@ -48,7 +48,11 @@ void log_start(void);
/*
* Generate a message and send it to the log thread.
*
- * Except for level, the arguments and return value are similar to printf().
+ * The arguments and return value are similar to printf(), with
+ * these exceptions :
+ * - a level is associated to each log message
+ * - processing stops at the first terminating null byte or newline
+ * character, whichever occurs first
*
* This function may safely be called in interrupt context.
*/