diff options
author | Craig A. Berry <craigberry@mac.com> | 2008-09-08 02:41:04 +0000 |
---|---|---|
committer | Craig A. Berry <craigberry@mac.com> | 2008-09-08 02:41:04 +0000 |
commit | c1c45e367d7249b259ceab21bde763fef82ddd7a (patch) | |
tree | c1bbcd93fd60037014ba9d2f7d752fc86d9ebabf /t/test.pl | |
parent | 3551ef6f06c9dcf7d75756f812148d56a3786992 (diff) | |
download | perl-c1c45e367d7249b259ceab21bde763fef82ddd7a.tar.gz |
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
Diffstat (limited to 't/test.pl')
-rw-r--r-- | t/test.pl | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -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); }; } } |