From 479b350ebf08248eb7729a02a07ddfe7a7c65e44 Mon Sep 17 00:00:00 2001 From: Greg Kurz Date: Fri, 4 Nov 2022 13:00:58 +0100 Subject: [PATCH] util/log: Make the per-thread flag immutable Per-thread logging was implemented under the assumption that once enabled, it is not possible to switch back to single file logging. This isn't enforced though and it is possible to go through the global file opening sequence in per-thread mode. The code isn't ready for this and produces unexpected results as detailed below. Start QEMU in system emulation mode with `-D ./qemu.log.%d -d tid` and then change the log level from the monitor to something that doesn't have tid, e.g. `log cpu_reset`. The value of log_flags is zero and per_thread is set to false : the rest of the code then assumes it is running in the global log case and opens a file named `qemu.log.%d`, which is obviously not an expected behavior. Enforce the immutability of the flag early in qemu_set_log_internal() so that its value is correct for all subsequent users. Fixes: 4e51069d6793 ("util/log: Support per-thread log files") Cc: richard.henderson@linaro.org Signed-off-by: Greg Kurz Reviewed-by: Richard Henderson Message-id: 20221104120059.678470-2-groug@kaod.org Signed-off-by: Stefan Hajnoczi --- util/log.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/util/log.c b/util/log.c index 39866bdaf2..b7d2b6e09c 100644 --- a/util/log.c +++ b/util/log.c @@ -206,6 +206,11 @@ static bool qemu_set_log_internal(const char *filename, bool changed_name, QEMU_LOCK_GUARD(&global_mutex); logfile = global_file; + /* The per-thread flag is immutable. */ + if (log_per_thread) { + log_flags |= LOG_PER_THREAD; + } + per_thread = log_flags & LOG_PER_THREAD; if (changed_name) {