From c1c45e367d7249b259ceab21bde763fef82ddd7a Mon Sep 17 00:00:00 2001 From: "Craig A. Berry" Date: Mon, 8 Sep 2008 02:41:04 +0000 Subject: [PATCH] Make sure the watchdog requeues itself when sleep() wakes up early (such as when an alarm fires). Also, bail out with SIGTERM rather than SIGKILL on VMS since the latter kills the shell from which Perl was started. p4raw-id: //depot/perl@34316 --- t/test.pl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/t/test.pl b/t/test.pl index fbb65db..8b3154e 100644 --- a/t/test.pl +++ b/t/test.pl @@ -843,10 +843,11 @@ sub watchdog ($) local $SIG{'__WARN__'} = sub { _diag("Watchdog warning: $_[0]"); }; + my $sig = $^O eq 'VMS' ? 'TERM' : 'KILL'; $watchdog = system(1, which_perl(), '-e', "sleep($timeout);" . "warn('# $timeout_msg\n');" . - "kill('KILL', $pid_to_kill);"); + "kill($sig, $pid_to_kill);"); }; if ($@ || ($watchdog <= 0)) { _diag('Failed to start watchdog'); @@ -908,13 +909,19 @@ sub watchdog ($) eval { require POSIX; }; # Execute the timeout - sleep($timeout); + my $time_elapsed = 0; + my $time_left = $timeout; + while ($time_elapsed < $timeout) { + $time_elapsed += sleep($time_left); + $time_left = $timeout - $time_elapsed; + } # Kill the parent (and ourself) select(STDERR); $| = 1; _diag($timeout_msg); POSIX::_exit(1) if (defined(&POSIX::_exit)); - kill('KILL', $pid_to_kill); + my $sig = $^O eq 'VMS' ? 'TERM' : 'KILL'; + kill($sig, $pid_to_kill); })->detach(); return; } @@ -929,7 +936,8 @@ sub watchdog ($) select(STDERR); $| = 1; _diag($timeout_msg); POSIX::_exit(1) if (defined(&POSIX::_exit)); - kill('KILL', $pid_to_kill); + my $sig = $^O eq 'VMS' ? 'TERM' : 'KILL'; + kill($sig, $pid_to_kill); }; } } -- 2.7.4