@samitouri / QOSamiQemu / commits / 13bedeb212

util: fix interleaving of error prefixes

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>

Daniel P. Berrangé committed Sep 24, 2025 at 18:55 UTC 13bedeb212e3173f8de60286a38f8a5cb57affd9
1 file changed +7
util/error-report.c
+7
@@ -233,6 +233,9 @@ static void vreport(report_type type, const char *fmt, va_list ap)
233 if (monitor_cur_is_qmp()) {
234 cur = NULL;
235 }
236 + if (!cur) {
237 + qemu_flockfile(stderr);
238 + }
239
240 if (message_with_timestamp && !cur) {
241 timestr = real_time_iso8601();
@@ -260,6 +263,10 @@ static void vreport(report_type type, const char *fmt, va_list ap)
263
264 error_vprintf_mon(cur, fmt, ap);
265 error_printf_mon(cur, "\n");
266 +
267 + if (!cur) {
268 + qemu_funlockfile(stderr);
269 + }
270 }
271
272 /*