diff options
author | Greg Kurz <groug@kaod.org> | 2022-11-04 13:00:58 +0100 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2022-11-07 16:00:02 -0500 |
commit | 479b350ebf08248eb7729a02a07ddfe7a7c65e44 (patch) | |
tree | 034b87efc91cb0f2157375dd58c1ff7d5c61f564 | |
parent | 622a84ef76e4fb91327651cc3294a589c341acb5 (diff) |
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 <groug@kaod.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20221104120059.678470-2-groug@kaod.org
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r-- | util/log.c | 5 |
1 files changed, 5 insertions, 0 deletions
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) { |