Hi Roland,

I get randomly a race
        reparent-zombie: reparent-zombie.c:88: create_zombie: Assertion `fd != 
-1' failed.
        Aborted
on kernel-2.6.25.3-18.fc9.x86_64.

I hope the attached patch is right (tested only for reparent-zombie.c as
reparent-zombie-clone.c is crashing the kernel).


Best Regards,
Jan
--- tests/reparent-zombie.c     2 May 2008 01:27:20 -0000       1.1
+++ tests/reparent-zombie.c     2 Jun 2008 12:40:01 -0000
@@ -78,15 +78,19 @@ create_zombie (void)
   assert (WIFSTOPPED (status));
   assert (WSTOPSIG (status) == SIGUSR1);
 
+  /* We must open the status file first as if CHILD would finish in between
+     TRACE_CONT and this OPEN we would fail with ENOSRCH as no zombie is left
+     as we have set the SIGCHLD handler to SIG_IGN (kernel reaps the died
+     children without creating any zombies.  */
+  snprintf (buf, sizeof buf, "/proc/%d/status", (int) child);
+  fd = open (buf, O_RDONLY);
+  assert (fd != -1);
+
   errno = 0;
   l = ptrace (PTRACE_CONT, child, 0l, 0l);
   assert_perror (errno);
   assert (l == 0);
 
-  snprintf (buf, sizeof buf, "/proc/%d/status", (int) child);
-  fd = open (buf, O_RDONLY);
-  assert (fd != -1);
-
   do
     {
       sched_yield ();
@@ -173,6 +177,8 @@ main (void)
   signal (SIGABRT, handler_fail);
   signal (SIGALRM, handler_fail);
 
+  /* SIG_IGN as we want no zombies left - kernel reaps the died children
+     without creating any zombies.  */
   signal (SIGCHLD, SIG_IGN);
 
   fd = create_zombie ();
--- tests/reparent-zombie-clone.c       2 May 2008 01:27:20 -0000       1.1
+++ tests/reparent-zombie-clone.c       2 Jun 2008 12:44:15 -0000
@@ -123,6 +123,14 @@ create_zombie (void)
   assert (WIFSTOPPED (status));
   assert (WSTOPSIG (status) == SIGSTOP);
 
+  /* We must open the status file first as if MSG would finish in between
+     TRACE_CONT and this OPEN we would fail with ENOSRCH as no zombie is left
+     as we have set the SIGCHLD handler to SIG_IGN (kernel reaps the died
+     children without creating any zombies.  */
+  snprintf (buf, sizeof buf, "/proc/%d/status", (int) msg);
+  fd = open (buf, O_RDONLY);
+  assert (fd != -1);
+
   errno = 0;
   l = ptrace (PTRACE_CONT, msg, 0l, 0l);
   assert_perror (errno);
@@ -135,10 +143,6 @@ create_zombie (void)
 
   child = msg;
 
-  snprintf (buf, sizeof buf, "/proc/%d/status", (int) child);
-  fd = open (buf, O_RDONLY);
-  assert (fd != -1);
-
   do
     {
       sched_yield ();
@@ -225,6 +229,8 @@ main (void)
   signal (SIGABRT, handler_fail);
   signal (SIGALRM, handler_fail);
 
+  /* SIG_IGN as we want no zombies left - kernel reaps the died children
+     without creating any zombies.  */
   signal (SIGCHLD, SIG_IGN);
 
   fd = create_zombie ();

Reply via email to