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

There was a race in the code where the pipes may not be read after the process 
has exited
and data may be left behind in them. This change to ordering ensures the pipes 
are read
after the exit code has been read meaning no data can be left behind and the 
logs should
be complete.

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

diff --git a/utils.c b/utils.c
index 86dcdad..ad737c2 100644
--- a/utils.c
+++ b/utils.c
@@ -285,6 +285,7 @@ wait_child(const char *ptest_dir, const char *run_ptest, 
pid_t pid,
        struct pollfd pfds[2];
        struct timespec sentinel;
        clockid_t clock = CLOCK_MONOTONIC;
+       int looping = 1;
        int r;
 
        int status;
@@ -302,9 +303,23 @@ wait_child(const char *ptest_dir, const char *run_ptest, 
pid_t pid,
 
        *timeouted = 0;
 
-       while (1) {
+       while (looping) {
                waitflags = WNOHANG;
 
+               if (timeout >= 0) {
+                       struct timespec time;
+
+                       clock_gettime(clock, &time);
+                       if ((time.tv_sec - sentinel.tv_sec) > timeout) {
+                               *timeouted = 1;
+                               kill(-pid, SIGKILL);
+                               waitflags = 0;
+                       }
+               }
+
+               if (waitpid(pid, &status, waitflags) == pid)
+                       looping = 0;
+
                r = poll(pfds, 2, WAIT_CHILD_POLL_TIMEOUT_MS);
                if (r > 0) {
                        char buf[WAIT_CHILD_BUF_MAX_SIZE];
@@ -324,19 +339,7 @@ wait_child(const char *ptest_dir, const char *run_ptest, 
pid_t pid,
                        }
 
                        clock_gettime(clock, &sentinel);
-               } else if (timeout >= 0) {
-                       struct timespec time;
-
-                       clock_gettime(clock, &time);
-                       if ((time.tv_sec - sentinel.tv_sec) > timeout) {
-                               *timeouted = 1;
-                               kill(-pid, SIGKILL);
-                               waitflags = 0;
-                       }
                }
-
-               if (waitpid(pid, &status, waitflags) == pid)
-                       break;
        }
 
        fflush(fps[0]);
-- 
2.17.0

-- 
_______________________________________________
yocto mailing list
yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/yocto

Reply via email to