diff mbox series

[PULL,for-7.1,15/36] util/log: Use qemu_log_lock/unlock in qemu_log

Message ID 20220320171135.2704502-16-richard.henderson@linaro.org
State Superseded
Headers show
Series Logging cleanup and per-thread logfiles | expand

Commit Message

Richard Henderson March 20, 2022, 5:11 p.m. UTC
Avoid using QemuLogFile and RCU directly.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 util/log.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Alex Bennée March 23, 2022, 5:28 p.m. UTC | #1
Richard Henderson <richard.henderson@linaro.org> writes:

> Avoid using QemuLogFile and RCU directly.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
diff mbox series

Patch

diff --git a/util/log.c b/util/log.c
index b1651d8122..3ec6e90575 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_lock();
     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;
 }