util/log: Always send errors to logfile when daemonized
commit9b063b7ea697d796914b3651d15c3457b7b1135c
authorGreg Kurz <groug@kaod.org>
Tue, 8 Nov 2022 14:00:32 +0000 (8 15:00 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 5 Jan 2023 23:50:32 +0000 (6 00:50 +0100)
tree705e7c196777f7310bc29955a0d859e2a8b0c6ea
parent59bde2137445b63c822720d069d91d38190c6540
util/log: Always send errors to logfile when daemonized

When QEMU is started with `-daemonize`, all stdio descriptors get
redirected to `/dev/null`. This basically means that anything
printed with error_report() and friends is lost.

Current logging code allows to redirect to a file with `-D` but
this requires to enable some logging item with `-d` as well to
be functional.

Relax the check on the log flags when QEMU is daemonized, so that
other users of stderr can benefit from the redirection, without the
need to enable unwanted debug logs. Previous behaviour is retained
for the non-daemonized case. The logic is unrolled as an `if` for
better readability. The qemu_log_level and log_per_thread globals
reflect the state we want to transition to at this point : use
them instead of the intermediary locals for correctness.

qemu_set_log_internal() is adapted to open a per-thread log file
when '-d tid' is passed. This is done by hijacking qemu_try_lock()
which seems simpler that refactoring the code.

Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <20221108140032.1460307-3-groug@kaod.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
util/log.c