On 9/10/25 18:03, Daniel P. Berrangé wrote:
Some code makes multiple qemu_log calls to incrementally emit
a single message. Currently timestamps get prepended to all
qemu_log calls, even those continuing a previous incomplete
message.
This changes the qemu_log so it skips adding a new line prefix,
if the previous qemu_log call did NOT end with a newline.
Reported-by: Richard Henderson <richard.hender...@linaro.org>
Signed-off-by: Daniel P. Berrangé <berra...@redhat.com>
---
util/log.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
Reviewed-by: Richard Henderson <richard.hender...@linaro.org>
r~>
diff --git a/util/log.c b/util/log.c
index abdcb6b311..2642a55c59 100644
--- a/util/log.c
+++ b/util/log.c
@@ -143,6 +143,12 @@ void qemu_log_unlock(FILE *logfile)
}
}
+/*
+ * 'true' if the previous log message lacked a trailing '\n',
+ * and thus the subsequent call must skip any prefix
+ */
+static __thread bool incomplete;
+
void qemu_log(const char *fmt, ...)
{
FILE *f;
@@ -154,7 +160,7 @@ void qemu_log(const char *fmt, ...)
* was emitted if we are delayed acquiring the
* mutex
*/
- if (message_with_timestamp) {
+ if (message_with_timestamp && !incomplete) {
g_autoptr(GDateTime) dt = g_date_time_new_now_utc();
timestr = g_date_time_format_iso8601(dt);
}
@@ -170,6 +176,7 @@ void qemu_log(const char *fmt, ...)
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
+ incomplete = fmt[strlen(fmt) - 1] != '\n';
qemu_log_unlock(f);
}
}