From 2bdbd07a1223e26c73caccb54f9af51f958c5b8f Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Sat, 24 Nov 2018 14:47:55 -0600 Subject: [PATCH] checks: Make each message output atomic Printing to stderr as we build up the check message results in interleaving of messages when multiple instances of dtc are running. Change the message output to use an intermediate buffer for constructing the message and then output the message to stderr with a single fputs. While perhaps there is no guarantee that fputs will be atomic, this gets rid of any interleaved output that previously occurred on Linux. Signed-off-by: Rob Herring Signed-off-by: David Gibson --- checks.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/checks.c b/checks.c index 4d8dffd..32e0d7a 100644 --- a/checks.c +++ b/checks.c @@ -78,23 +78,28 @@ static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti, const char *fmt, ...) { va_list ap; + char *str = NULL; if (!(c->warn && (quiet < 1)) && !(c->error && (quiet < 2))) return; - fprintf(stderr, "%s: %s (%s): ", + xasprintf(&str, "%s: %s (%s): ", strcmp(dti->outname, "-") ? dti->outname : "", (c->error) ? "ERROR" : "Warning", c->name); if (node) { - fprintf(stderr, "%s", node->fullpath); if (prop) - fprintf(stderr, ":%s", prop->name); - fputs(": ", stderr); + xasprintf_append(&str, "%s:%s: ", node->fullpath, prop->name); + else + xasprintf_append(&str, "%s: ", node->fullpath); } + va_start(ap, fmt); - vfprintf(stderr, fmt, ap); + xavsprintf_append(&str, fmt, ap); va_end(ap); - fprintf(stderr, "\n"); + + xasprintf_append(&str, "\n"); + + fputs(str, stderr); } #define FAIL(c, dti, node, ...) \