Fixed SIGALRM race.
authorlace <>
Fri, 15 Jun 2007 15:09:44 +0000 (15:09 +0000)
committerlace <>
Fri, 15 Jun 2007 15:09:44 +0000 (15:09 +0000)
 - It was reproducing only on UTRACE but it was a testsuite bug.

testsuite.c

index 4bfcd4f..76a3d09 100644 (file)
@@ -179,14 +179,12 @@ static void child_alrm_handler (int signo)
 
 static __attribute__((__noreturn__)) void child_alrm (void)
 {
-  void (*handler_orig) (int signo);
 #if 0
   int i;
   sigset_t oldset;
 #endif
 
-  handler_orig = signal (SIGALRM, child_alrm_handler);
-  assert (handler_orig == SIG_DFL);
+  /* Assumed already setup SIGALRM for CHILD_ALRM_HANDLER.  */
 
 #if 0
   i = sigprocmask (SIG_BLOCK, NULL, &oldset);
@@ -343,6 +341,7 @@ static void body_spawner (void *(*child) (void *data, void *input), void *data,
   pid_t inferior;
   struct attach_state_struct *attach_state;
   int i;
+  void (*handler_orig) (int signo);
 
   assert (input == NULL);
 
@@ -376,7 +375,12 @@ static void body_spawner (void *(*child) (void *data, void *input), void *data,
   murder (inferior);
 
   /* Attach to a stopped process with already pending SIGALRM.  */
+  /* Setup the handler already in the parent to avoid the child race.  */
+  handler_orig = signal (SIGALRM, child_alrm_handler);
+  assert (handler_orig == SIG_DFL);
   inferior = (unsigned long) (*child) (data, child_alrm);
+  handler_orig = signal (SIGALRM, handler_orig);
+  assert (handler_orig == child_alrm_handler);
   STATE (inferior, 1 << STATE_SLEEPING);
   delay ();
   i = tkill (inferior, SIGSTOP);