about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRoland McGrath <roland@hack.frob.com>2013-06-13 15:09:29 -0700
committerRoland McGrath <roland@hack.frob.com>2013-06-13 15:09:29 -0700
commita58ad3f801960fa0dc0bb1106eb0d99f7ebd77b1 (patch)
tree10616aeeaf186b442bcde2503abd50ea53b9bcca
parent5865a56bf4e31c5a152e46454367a99c5971ac02 (diff)
downloadglibc-a58ad3f801960fa0dc0bb1106eb0d99f7ebd77b1.tar.gz
glibc-a58ad3f801960fa0dc0bb1106eb0d99f7ebd77b1.tar.xz
glibc-a58ad3f801960fa0dc0bb1106eb0d99f7ebd77b1.zip
Fix raciness in waitid test.
-rw-r--r--ChangeLog7
-rw-r--r--posix/tst-waitid.c15
2 files changed, 18 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 985173df5e..494c919774 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-06-13  Roland McGrath  <roland@hack.frob.com>
+
+	* posix/tst-waitid.c (do_test): Distinguish different instances of
+	stopped/continued in CHECK_SIGCHLD uses.  Insert a delay between
+	sending SIGSTOP and calling waitpid to ensure SIGCHLD gets delivered
+	before entering the kernel for waitpid.
+
 2013-06-13  Siddhesh Poyarekar  <siddhesh@redhat.com>
 
 	* NEWS: Fix note on clock function precision.  Text by Roland
diff --git a/posix/tst-waitid.c b/posix/tst-waitid.c
index ad3df5a329..57a6a3f769 100644
--- a/posix/tst-waitid.c
+++ b/posix/tst-waitid.c
@@ -145,7 +145,7 @@ do_test (int argc, char *argv[])
   /* Give the child a chance to stop.  */
   sleep (3);
 
-  CHECK_SIGCHLD ("stopped", CLD_STOPPED, SIGSTOP);
+  CHECK_SIGCHLD ("stopped (before waitid)", CLD_STOPPED, SIGSTOP);
 
   /* Now try a wait that should not succeed.  */
   siginfo_t info;
@@ -227,7 +227,7 @@ do_test (int argc, char *argv[])
       expecting_sigchld = 0;
     }
   else
-    CHECK_SIGCHLD ("continued", CLD_CONTINUED, SIGCONT);
+    CHECK_SIGCHLD ("continued (before waitid)", CLD_CONTINUED, SIGCONT);
 
   info.si_signo = 0;		/* A successful call sets it to SIGCHLD.  */
   info.si_pid = -1;
@@ -336,6 +336,13 @@ do_test (int argc, char *argv[])
       printf ("kill (%d, SIGSTOP): %m\n", pid);
       RETURN (EXIT_FAILURE);
     }
+
+  /* Give the child a chance to stop.  The waitpid call below will block
+     until it has stopped, but if we are real quick and enter the waitpid
+     system call before the SIGCHLD has been generated, then it will be
+     discarded and never delivered.  */
+  sleep (3);
+
   pid_t wpid = waitpid (pid, &fail, WUNTRACED);
   if (wpid < 0)
     {
@@ -354,7 +361,7 @@ do_test (int argc, char *argv[])
       printf ("waitpid WUNTRACED on stopped: status %x\n", fail);
       RETURN (EXIT_FAILURE);
     }
-  CHECK_SIGCHLD ("stopped", CLD_STOPPED, SIGSTOP);
+  CHECK_SIGCHLD ("stopped (after waitpid)", CLD_STOPPED, SIGSTOP);
 
   expecting_sigchld = 1;
   if (kill (pid, SIGCONT) != 0)
@@ -372,7 +379,7 @@ do_test (int argc, char *argv[])
       expecting_sigchld = 0;
     }
   else
-    CHECK_SIGCHLD ("continued", CLD_CONTINUED, SIGCONT);
+    CHECK_SIGCHLD ("continued (before waitpid)", CLD_CONTINUED, SIGCONT);
 
   wpid = waitpid (pid, &fail, WCONTINUED);
   if (wpid < 0)