]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
util: fix interleaving of error prefixes
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 24 Sep 2025 17:55:21 +0000 (18:55 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 5 Mar 2026 17:40:24 +0000 (17:40 +0000)
The vreport() function will optionally emit an prefix for error
messages which is output to stderr incrementally. In the event
that two vreport() calls execute concurrently, there is a risk
that the prefix output will interleave. To address this it is
required to take a lock on 'stderr' when outputting errors.

Reported-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
util/error-report.c

index 6b9e592bc14fe7508b5f959c300711933af51709..bbea49a55d22d9895d20c72a29df86af7c78d023 100644 (file)
@@ -233,6 +233,9 @@ static void vreport(report_type type, const char *fmt, va_list ap)
     if (monitor_cur_is_qmp()) {
         cur = NULL;
     }
+    if (!cur) {
+        qemu_flockfile(stderr);
+    }
 
     if (message_with_timestamp && !cur) {
         timestr = real_time_iso8601();
@@ -260,6 +263,10 @@ static void vreport(report_type type, const char *fmt, va_list ap)
 
     error_vprintf_mon(cur, fmt, ap);
     error_printf_mon(cur, "\n");
+
+    if (!cur) {
+        qemu_funlockfile(stderr);
+    }
 }
 
 /*