From 336018b493e7eeae79b163f495d0471c01ce1863 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Thu, 18 Dec 2014 15:55:30 +0100 Subject: [PATCH] base: append label per line properly (log service) If newlines are in the string send to the core log service, they don't get the label properly appended before each output. The messages then look like they are coming from core. Fixes #1368 --- .../src/core/include/log_session_component.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/repos/base/src/core/include/log_session_component.h b/repos/base/src/core/include/log_session_component.h index b4fc7a7b8..149ac922a 100644 --- a/repos/base/src/core/include/log_session_component.h +++ b/repos/base/src/core/include/log_session_component.h @@ -52,7 +52,7 @@ namespace Genode { } char const *string = string_buf.string(); - int len = strlen(string); + size_t len = strlen(string); /* * Heuristic: The Log console implementation flushes @@ -70,11 +70,21 @@ namespace Genode { return len; } - printf("[%s] %s", _label, string); + char buf[string_buf.MAX_SIZE]; + unsigned from_i = 0; + + for (unsigned i = 0; i < len; i++) { + if (string[i] == '\n') { + memcpy(buf, string + from_i, i - from_i); + buf[i - from_i] = 0; + printf("[%s] %s\n", _label, buf); + from_i = i + 1; + } + } /* if last character of string was not a line break, add one */ - if ((len > 0) && (string[len - 1] != '\n')) - printf("\n"); + if (from_i < len) + printf("[%s] %s\n", _label, string + from_i); return len; }