From 524fc737431d240f9d9f10aaf381003092868bac Mon Sep 17 00:00:00 2001 From: Greg Kurz Date: Fri, 4 Nov 2022 13:00:59 +0100 Subject: [PATCH] util/log: Ignore per-thread flag if global file already there If QEMU is started with `-D qemu.log.%d` without any `-d` option, doing `log all` in the monitor fails with: Filename template with '%d' required for 'tid' It is confusing since '%d' was actually passed. This happens because QEMU caches the log file name with %d converted to getpid() since `tid` wasn't required. This name isn't suitable for a subsequent enablement of per-thread logs. There's little cause to change the behavior as `-d tid` is mostly used at user-only startup. Drop the per-thread from the requested flags in this case : `log all` will thus enable everything except `tid` instead of failing. This is preferable over forcing the user to enable each log item individually. With this patch, `tid` is now truely immutable : it can only be set or unset from the command line and never changed afterwards. 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-3-groug@kaod.org Signed-off-by: Stefan Hajnoczi --- util/log.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/log.c b/util/log.c index b7d2b6e09c..c2198badf2 100644 --- a/util/log.c +++ b/util/log.c @@ -209,6 +209,10 @@ static bool qemu_set_log_internal(const char *filename, bool changed_name, /* The per-thread flag is immutable. */ if (log_per_thread) { log_flags |= LOG_PER_THREAD; + } else { + if (global_filename) { + log_flags &= ~LOG_PER_THREAD; + } } per_thread = log_flags & LOG_PER_THREAD;