This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix test-skeleton.c timeout handling


Hi!

If waitpid returns 0, timeout_handler would still happily access the random
value in status.

2003-06-19  Jakub Jelinek  <jakub@redhat.com>

	* test-skeleton.c (timeout_handler): If waitpid returned 0,
	retry once after a second.  If killed == 0, assume
	WTERMSIG (status) == SIGKILL.

--- libc/test-skeleton.c.jj	2003-06-07 19:23:01.000000000 -0400
+++ libc/test-skeleton.c	2003-06-19 05:40:53.000000000 -0400
@@ -140,9 +140,14 @@ timeout_handler (int sig __attribute__ (
 
   /* Wait for it to terminate.  */
   killed = waitpid (pid, &status, WNOHANG|WUNTRACED);
+  if (killed == 0)
+    {
+      sleep (1);
+      killed = waitpid (pid, &status, WNOHANG|WUNTRACED);
+    }
   if (killed != 0 && killed != pid)
     {
-      perror ("Failed to killed test process");
+      perror ("Failed to kill test process");
       exit (1);
     }
 
@@ -156,7 +161,7 @@ timeout_handler (int sig __attribute__ (
     exit (0);
 #endif
 
-  if (WIFSIGNALED (status) && WTERMSIG (status) == SIGKILL)
+  if (killed == 0 || (WIFSIGNALED (status) && WTERMSIG (status) == SIGKILL))
     fputs ("Timed out: killed the child process\n", stderr);
   else if (WIFSTOPPED (status))
     fprintf (stderr, "Timed out: the child process was %s\n",

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]