diff mbox series

[v1,1/4] common.h: Flush stdout before writing to stderr

Message ID 2e89973f61bbd6e6ebb423ec6fe7a025d5404235.1673623880.git.mstrasun@amazon.com (mailing list archive)
State New, archived
Headers show
Series Collection of livepatch-build-tools tweaks | expand

Commit Message

Mihails Strasuns Jan. 19, 2023, 10:13 a.m. UTC
Flush existing debug messages before writing an error to stderr.  stderr
is usually unbuffered and stdout is usually buffered. This results in
odd looking output when an error occurs and both stderr/stdout are
printed on the same console/file. More precisely, the error message is
printed in the middle of previously emitted debug messages.

Signed-off-by: Michael Kurth <mku@amazon.com>
---
 common.h | 1 +
 1 file changed, 1 insertion(+)

Comments

Ross Lagerwall Feb. 8, 2023, 6:02 p.m. UTC | #1
> From: Xen-devel <xen-devel-bounces@lists.xenproject.org> on behalf of Mihails Strasuns <mstrasun@amazon.com>
> Sent: Thursday, January 19, 2023 10:13 AM
> To: xen-devel@lists.xenproject.org <xen-devel@lists.xenproject.org>
> Cc: mstrasun@amazon.com <mstrasun@amazon.com>; Michael Kurth <mku@amazon.com>
> Subject: [PATCH v1 1/4] common.h: Flush stdout before writing to stderr 
>  
> Flush existing debug messages before writing an error to stderr.  stderr
> is usually unbuffered and stdout is usually buffered. This results in
> odd looking output when an error occurs and both stderr/stdout are
> printed on the same console/file. More precisely, the error message is
> printed in the middle of previously emitted debug messages.
> 
> Signed-off-by: Michael Kurth <mku@amazon.com>
> ---
>  common.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/common.h b/common.h
> index 02c9b7b..9a9da79 100644
> --- a/common.h
> +++ b/common.h
> @@ -10,6 +10,7 @@ extern char *childobj;
>  
>  #define DIFF_FATAL(format, ...) \
>  ({ \
> +       fflush(stdout); \
>          fprintf(stderr, "ERROR: %s: " format "\n", childobj, ##__VA_ARGS__); \
>          error(2, 0, "unreconcilable difference"); \
>  })
> -- 
> 2.38.1

Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
diff mbox series

Patch

diff --git a/common.h b/common.h
index 02c9b7b..9a9da79 100644
--- a/common.h
+++ b/common.h
@@ -10,6 +10,7 @@  extern char *childobj;
 
 #define DIFF_FATAL(format, ...) \
 ({ \
+	fflush(stdout); \
 	fprintf(stderr, "ERROR: %s: " format "\n", childobj, ##__VA_ARGS__); \
 	error(2, 0, "unreconcilable difference"); \
 })