From 095e9855b774b9da9b84c9cf21cbd856ae482670 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Sun, 17 Apr 2022 11:29:56 -0700 Subject: [PATCH] util/log: Use qemu_log_trylock/unlock in qemu_log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid using QemuLogFile and RCU directly. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson Message-Id: <20220417183019.755276-17-richard.henderson@linaro.org> --- util/log.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/util/log.c b/util/log.c index 6b7b358573..090bc3bc39 100644 --- a/util/log.c +++ b/util/log.c @@ -62,23 +62,22 @@ void qemu_log_unlock(FILE *fd) /* Return the number of characters emitted. */ int qemu_log(const char *fmt, ...) { + FILE *f = qemu_log_trylock(); int ret = 0; - QemuLogFile *logfile; - rcu_read_lock(); - logfile = qatomic_rcu_read(&qemu_logfile); - if (logfile) { + if (f) { va_list ap; + va_start(ap, fmt); - ret = vfprintf(logfile->fd, fmt, ap); + ret = vfprintf(f, fmt, ap); va_end(ap); + qemu_log_unlock(f); /* Don't pass back error results. */ if (ret < 0) { ret = 0; } } - rcu_read_unlock(); return ret; }