bdc76f
commit 114f792eaea2505cd8aee02d330aad37238da6a5
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Fri Feb 1 11:03:35 2019 +0100
bdc76f
bdc76f
    posix/tst-spawn: Fix racy tests in spawned processes.
bdc76f
    
bdc76f
    From time to time I get fails in tst-spawn like:
bdc76f
    tst-spawn.c:111: numeric comparison failure
bdc76f
       left: 0 (0x0); from: xlseek (fd2, 0, SEEK_CUR)
bdc76f
      right: 28 (0x1c); from: strlen (fd2string)
bdc76f
    error: 1 test failures
bdc76f
    tst-spawn.c:252: numeric comparison failure
bdc76f
       left: 1 (0x1); from: WEXITSTATUS (status)
bdc76f
      right: 0 (0x0); from: 0
bdc76f
    error: 1 test failures
bdc76f
    
bdc76f
    It turned out, that a child process is testing it's open file descriptors
bdc76f
    with e.g. a sequence of testing the current position, setting the position
bdc76f
    to zero and reading a specific amount of bytes.
bdc76f
    
bdc76f
    Unfortunately starting with commit 2a69f853c03034c2e383e0f9c35b5402ce8b5473
bdc76f
    the test is spawning a second child process which is sharing some of the
bdc76f
    file descriptors.  If the test sequence as mentioned above is running in parallel
bdc76f
    it leads to test failures.
bdc76f
    
bdc76f
    As the second call of posix_spawn shall test a NULL pid argument,
bdc76f
    this patch is just moving the waitpid of the first child
bdc76f
    before the posix_spawn of the second child.
bdc76f
    
bdc76f
    ChangeLog:
bdc76f
    
bdc76f
            * posix/tst-spawn do_test(): Move waitpid before posix_spawn.
bdc76f
bdc76f
diff --git a/posix/tst-spawn.c b/posix/tst-spawn.c
bdc76f
index eea5addbf3..9aa7e621e6 100644
bdc76f
--- a/posix/tst-spawn.c
bdc76f
+++ b/posix/tst-spawn.c
bdc76f
@@ -237,6 +237,12 @@ do_test (int argc, char *argv[])
bdc76f
   TEST_COMPARE (posix_spawn (&pid, argv[1], &actions, NULL, spargv, environ),
bdc76f
 		0);
bdc76f
 
bdc76f
+  /* Wait for the children.  */
bdc76f
+  TEST_COMPARE (xwaitpid (pid, &status, 0), pid);
bdc76f
+  TEST_VERIFY (WIFEXITED (status));
bdc76f
+  TEST_VERIFY (!WIFSIGNALED (status));
bdc76f
+  TEST_COMPARE (WEXITSTATUS (status), 0);
bdc76f
+
bdc76f
   /* Same test but with a NULL pid argument.  */
bdc76f
   TEST_COMPARE (posix_spawn (NULL, argv[1], &actions, NULL, spargv, environ),
bdc76f
 		0);
bdc76f
@@ -246,11 +252,6 @@ do_test (int argc, char *argv[])
bdc76f
   free (name3_copy);
bdc76f
 
bdc76f
   /* Wait for the children.  */
bdc76f
-  TEST_COMPARE (xwaitpid (pid, &status, 0), pid);
bdc76f
-  TEST_VERIFY (WIFEXITED (status));
bdc76f
-  TEST_VERIFY (!WIFSIGNALED (status));
bdc76f
-  TEST_COMPARE (WEXITSTATUS (status), 0);
bdc76f
-
bdc76f
   xwaitpid (-1, &status, 0);
bdc76f
   TEST_VERIFY (WIFEXITED (status));
bdc76f
   TEST_VERIFY (!WIFSIGNALED (status));