blob: f7c3ebe6f2cebe521f24471ee0245271d435f3e5 [file] [log] [blame]
Brad Bishopd89cb5f2019-04-10 09:02:41 -04001From e58e4e1a7f854953f823dc5135d35f728f253f31 Mon Sep 17 00:00:00 2001
2From: Richard Purdie <richard.purdie@linuxfoundation.org>
3Date: Thu, 4 Apr 2019 14:24:14 +0100
4Subject: [PATCH 3/3] utils: Ensure pipes are read after exit
5
6There was a race in the code where the pipes may not be read after the process has exited
7and data may be left behind in them. This change to ordering ensures the pipes are read
8after the exit code has been read meaning no data can be left behind and the logs should
9be complete.
10
11Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
12Upstream-Status: Pending [code being tested]
13---
14 utils.c | 29 ++++++++++++++++-------------
15 1 file changed, 16 insertions(+), 13 deletions(-)
16
17diff --git a/utils.c b/utils.c
18index c5b3b8d..37e88ab 100644
19--- a/utils.c
20+++ b/utils.c
21@@ -264,6 +264,7 @@ wait_child(const char *ptest_dir, const char *run_ptest, pid_t pid, pid_t group,
22 struct pollfd pfds[2];
23 struct timespec sentinel;
24 clockid_t clock = CLOCK_MONOTONIC;
25+ int looping = 1;
26 int r;
27
28 int status;
29@@ -281,9 +282,23 @@ wait_child(const char *ptest_dir, const char *run_ptest, pid_t pid, pid_t group,
30
31 *timeouted = 0;
32
33- while (1) {
34+ while (looping) {
35 waitflags = WNOHANG;
36
37+ if (timeout >= 0) {
38+ struct timespec time;
39+
40+ clock_gettime(clock, &time);
41+ if ((time.tv_sec - sentinel.tv_sec) > timeout) {
42+ *timeouted = 1;
43+ kill(-pid, SIGKILL);
44+ waitflags = 0;
45+ }
46+ }
47+
48+ if (waitpid(pid, &status, waitflags) == pid)
49+ looping = 0;
50+
51 r = poll(pfds, 2, WAIT_CHILD_POLL_TIMEOUT_MS);
52 if (r > 0) {
53 char buf[WAIT_CHILD_BUF_MAX_SIZE];
54@@ -303,19 +318,7 @@ wait_child(const char *ptest_dir, const char *run_ptest, pid_t pid, pid_t group,
55 }
56
57 clock_gettime(clock, &sentinel);
58- } else if (timeout >= 0) {
59- struct timespec time;
60-
61- clock_gettime(clock, &time);
62- if ((time.tv_sec - sentinel.tv_sec) > timeout) {
63- *timeouted = 1;
64- kill(-pid, SIGKILL);
65- waitflags = 0;
66- }
67 }
68-
69- if (waitpid(pid, &status, waitflags) == pid)
70- break;
71 }
72
73 fflush(fps[0]);
74--
752.17.1
76