diff mbox series

[2/2] util/log: Ignore per-thread flag if global file already there

Message ID 20221104120059.678470-3-groug@kaod.org
State New
Headers show
Series util/log: Make the per-thread flag immutable | expand

Commit Message

Greg Kurz Nov. 4, 2022, noon UTC
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 <groug@kaod.org>
---
 util/log.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/util/log.c b/util/log.c
index b7d2b6e09cfe..c2198badf240 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;