[PATCH] Fix test-skeleton.c timeout handling
Jakub Jelinek
jakub@redhat.com
Thu Jun 19 11:37:00 GMT 2003
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
More information about the Libc-hacker
mailing list