[PATCH v4 17/23] util: fix interleaving of error prefixes

Daniel P. Berrangé posted 23 patches 3 days, 5 hours ago
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, Christian Schoenebeck <qemu_oss@crudebyte.com>, Markus Armbruster <armbru@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Dr. David Alan Gilbert" <dave@treblig.org>, Manos Pitsidianakis <manos.pitsidianakis@linaro.org>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Stefan Weil <sw@weilnetz.de>
[PATCH v4 17/23] util: fix interleaving of error prefixes
Posted by Daniel P. Berrangé 3 days, 5 hours ago
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.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 util/error-report.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/util/error-report.c b/util/error-report.c
index 222c40d0d1..b6aa20dbae 100644
--- a/util/error-report.c
+++ b/util/error-report.c
@@ -226,6 +226,8 @@ static void vreport(report_type type, const char *fmt, va_list ap)
 
     if (monitor_cur_is_hmp()) {
         cur = monitor_cur();
+    } else {
+        flockfile(stderr);
     }
 
     if (message_with_timestamp && !cur) {
@@ -254,6 +256,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) {
+        funlockfile(stderr);
+    }
 }
 
 /*
-- 
2.50.1


Re: [PATCH v4 17/23] util: fix interleaving of error prefixes
Posted by Richard Henderson 2 days, 18 hours ago
On 9/25/25 02:44, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   util/error-report.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/util/error-report.c b/util/error-report.c
> index 222c40d0d1..b6aa20dbae 100644
> --- a/util/error-report.c
> +++ b/util/error-report.c
> @@ -226,6 +226,8 @@ static void vreport(report_type type, const char *fmt, va_list ap)
>   
>       if (monitor_cur_is_hmp()) {
>           cur = monitor_cur();
> +    } else {
> +        flockfile(stderr);

qemu_f{un}lockfile.

Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

Re: [PATCH v4 17/23] util: fix interleaving of error prefixes
Posted by Philippe Mathieu-Daudé 3 days, 4 hours ago
On 25/9/25 11:44, Daniel P. Berrangé wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   util/error-report.c | 6 ++++++
>   1 file changed, 6 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>