All of lore.kernel.org
 help / color / mirror / Atom feed
From: Randy MacLeod <Randy.MacLeod@windriver.com>
To: <yocto@yoctoproject.org>, <anibal.limon@linaro.org>
Subject: [ptest-runner][PATCH v2 1/4] utils: Ensure stdout/stderr are flushed
Date: Fri, 14 Jun 2019 10:48:50 -0400	[thread overview]
Message-ID: <20190614144853.25839-2-Randy.MacLeod@windriver.com> (raw)
In-Reply-To: <20190614144853.25839-1-Randy.MacLeod@windriver.com>

From: Richard Purdie <richard.purdie@linuxfoundation.org>

There is no guarantee that the data written with fwrite will be flushed to the
buffer. If stdout and stderr are the same thing, this could lead to interleaved
writes. The common case is stdout output so flush the output pipes when writing to
stderr. Also flush stdout before the function returns.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Upstream-Status: Pending [code being tested]
---
 utils.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/utils.c b/utils.c
index 6e453a1..9fab6f2 100644
--- a/utils.c
+++ b/utils.c
@@ -316,8 +316,11 @@ wait_child(const char *ptest_dir, const char *run_ptest, pid_t pid,
 			}
 
 			if (pfds[1].revents != 0) {
-				while ((n = read(fds[1], buf, WAIT_CHILD_BUF_MAX_SIZE)) > 0)
+				while ((n = read(fds[1], buf, WAIT_CHILD_BUF_MAX_SIZE)) > 0) {
+					fflush(fps[0]);
 					fwrite(buf, n, 1, fps[1]);
+					fflush(fps[1]);
+				}
 			}
 
 			clock_gettime(clock, &sentinel);
@@ -336,7 +339,7 @@ wait_child(const char *ptest_dir, const char *run_ptest, pid_t pid,
 			break;
 	}
 
-
+	fflush(fps[0]);
 	return status;
 }
 
-- 
2.17.0



  reply	other threads:[~2019-06-14 14:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-13 22:39 [ptest-runner][PATCH] utils: ensure child can be session leader Randy MacLeod
2019-06-13 23:01 ` Randy MacLeod
2019-06-14 14:48 ` [ptest-runner][PATCH v2] 3 old patches + " Randy MacLeod
2019-06-14 14:48   ` Randy MacLeod [this message]
2019-06-14 14:48   ` [ptest-runner][PATCH v2 2/4] use process groups when spawning Randy MacLeod
2019-06-14 14:48   ` [ptest-runner][PATCH v2 3/4] utils: Ensure pipes are read after exit Randy MacLeod
2019-06-14 14:48   ` [ptest-runner][PATCH v2 4/4] utils: ensure child can be session leader Randy MacLeod
2019-06-19 17:49     ` Randy MacLeod
2019-06-19 19:24       ` richard.purdie
2019-06-19 19:54         ` Randy MacLeod
2019-06-26  1:51       ` Anibal Limon
2019-06-26  6:56         ` richard.purdie
2019-06-26 15:55         ` Randy MacLeod
2019-06-27 15:27           ` Anibal Limon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190614144853.25839-2-Randy.MacLeod@windriver.com \
    --to=randy.macleod@windriver.com \
    --cc=anibal.limon@linaro.org \
    --cc=yocto@yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.