0b0d35
commit a58ad3f801960fa0dc0bb1106eb0d99f7ebd77b1
0b0d35
Author: Roland McGrath <roland@hack.frob.com>
0b0d35
Date:   Thu Jun 13 15:09:29 2013 -0700
0b0d35
0b0d35
    Fix raciness in waitid test.
0b0d35
0b0d35
diff --git a/posix/tst-waitid.c b/posix/tst-waitid.c
0b0d35
index f8a302ea3153a853..d63ad65fbefc64ad 100644
0b0d35
--- a/posix/tst-waitid.c
0b0d35
+++ b/posix/tst-waitid.c
0b0d35
@@ -145,7 +145,7 @@ do_test (int argc, char *argv[])
0b0d35
   /* Give the child a chance to stop.  */
0b0d35
   sleep (3);
0b0d35
 
0b0d35
-  CHECK_SIGCHLD ("stopped", CLD_STOPPED, SIGSTOP);
0b0d35
+  CHECK_SIGCHLD ("stopped (before waitid)", CLD_STOPPED, SIGSTOP);
0b0d35
 
0b0d35
   /* Now try a wait that should not succeed.  */
0b0d35
   siginfo_t info;
0b0d35
@@ -227,7 +227,7 @@ do_test (int argc, char *argv[])
0b0d35
       expecting_sigchld = 0;
0b0d35
     }
0b0d35
   else
0b0d35
-    CHECK_SIGCHLD ("continued", CLD_CONTINUED, SIGCONT);
0b0d35
+    CHECK_SIGCHLD ("continued (before waitid)", CLD_CONTINUED, SIGCONT);
0b0d35
 
0b0d35
   info.si_signo = 0;		/* A successful call sets it to SIGCHLD.  */
0b0d35
   info.si_pid = -1;
0b0d35
@@ -336,6 +336,13 @@ do_test (int argc, char *argv[])
0b0d35
       printf ("kill (%d, SIGSTOP): %m\n", pid);
0b0d35
       RETURN (EXIT_FAILURE);
0b0d35
     }
0b0d35
+
0b0d35
+  /* Give the child a chance to stop.  The waitpid call below will block
0b0d35
+     until it has stopped, but if we are real quick and enter the waitpid
0b0d35
+     system call before the SIGCHLD has been generated, then it will be
0b0d35
+     discarded and never delivered.  */
0b0d35
+  sleep (3);
0b0d35
+
0b0d35
   pid_t wpid = waitpid (pid, &fail, WUNTRACED);
0b0d35
   if (wpid < 0)
0b0d35
     {
0b0d35
@@ -354,7 +361,7 @@ do_test (int argc, char *argv[])
0b0d35
       printf ("waitpid WUNTRACED on stopped: status %x\n", fail);
0b0d35
       RETURN (EXIT_FAILURE);
0b0d35
     }
0b0d35
-  CHECK_SIGCHLD ("stopped", CLD_STOPPED, SIGSTOP);
0b0d35
+  CHECK_SIGCHLD ("stopped (after waitpid)", CLD_STOPPED, SIGSTOP);
0b0d35
 
0b0d35
   expecting_sigchld = 1;
0b0d35
   if (kill (pid, SIGCONT) != 0)
0b0d35
@@ -372,7 +379,7 @@ do_test (int argc, char *argv[])
0b0d35
       expecting_sigchld = 0;
0b0d35
     }
0b0d35
   else
0b0d35
-    CHECK_SIGCHLD ("continued", CLD_CONTINUED, SIGCONT);
0b0d35
+    CHECK_SIGCHLD ("continued (before waitpid)", CLD_CONTINUED, SIGCONT);
0b0d35
 
0b0d35
   wpid = waitpid (pid, &fail, WCONTINUED);
0b0d35
   if (wpid < 0)