@@ -1846,19 +1846,19 @@ ($;$)
18461846 # If cancelling, use the state variables to know which method was used to
18471847 # create the watchdog.
18481848 if ($timeout == 0) {
1849- if ($watchdog_thread ) {
1850- $watchdog_thread -> kill (' KILL' );
1851- undef $watchdog_thread ;
1852- }
1853- elsif ($watchdog ) {
1854- kill (' KILL' , $watchdog );
1855- undef $watchdog ;
1856- }
1857- else {
1858- alarm(0);
1859- }
1849+ if ($watchdog_thread ) {
1850+ $watchdog_thread -> kill (' KILL' );
1851+ undef $watchdog_thread ;
1852+ }
1853+ elsif ($watchdog ) {
1854+ kill (' KILL' , $watchdog );
1855+ undef $watchdog ;
1856+ }
1857+ else {
1858+ alarm(0);
1859+ }
18601860
1861- return ;
1861+ return ;
18621862 }
18631863
18641864 # Make sure these aren't defined.
@@ -1890,8 +1890,7 @@ ($;$)
18901890 # shut up use only once warning
18911891 my $threads_on = $threads::threads && $threads::threads ;
18921892
1893- # Don't use a watchdog process if 'threads' is loaded -
1894- # use a watchdog thread instead
1893+ # Use a watchdog process unless 'threads' is loaded
18951894 if (!$threads_on || $method eq " process" ) {
18961895
18971896 # On Windows and VMS, try launching a watchdog process
@@ -1914,9 +1913,9 @@ ($;$)
19141913 undef $watchdog ;
19151914 eval {
19161915 local $SIG {' __WARN__' } = sub {
1917- _diag(" Watchdog warning: $_ [0]" );
1918- };
1919- my $sig = $is_vms ? ' TERM' : ' KILL' ;
1916+ _diag(" Watchdog warning: $_ [0]" );
1917+ };
1918+ my $sig = ( $is_vms ) ? ' TERM' : ' KILL' ;
19201919 my $prog = " sleep($timeout );" .
19211920 " warn qq/# $timeout_msg " . ' \n/;' .
19221921 " kill(q/$sig /, $pid_to_kill );" ;
@@ -1952,8 +1951,8 @@ ($;$)
19521951 return ;
19531952 }
19541953
1955- # Add END block to parent to terminate and
1956- # clean up watchdog process
1954+ # Add END block to parent to terminate and clean up watchdog
1955+ # process
19571956 eval (" END { local \$ ! = 0; local \$ ? = 0;
19581957 wait() if kill('KILL', $watchdog ); };" );
19591958 return ;
@@ -1964,8 +1963,8 @@ ($;$)
19641963 eval { $watchdog = fork () };
19651964 if (defined ($watchdog )) {
19661965 if ($watchdog ) { # Parent process
1967- # Add END block to parent to terminate and
1968- # clean up watchdog process
1966+ # Add END block to parent to terminate and clean up watchdog
1967+ # process
19691968 eval " END { local \$ ! = 0; local \$ ? = 0;
19701969 wait() if kill('KILL', $watchdog ); };" ;
19711970 return ;
@@ -2002,8 +2001,8 @@ ($;$)
20022001 # fork() failed - fall through and try using a thread
20032002 }
20042003
2005- # Use a watchdog thread because either 'threads' is loaded,
2006- # or fork() failed
2004+ # Use a watchdog thread because either 'threads' is loaded, or fork()
2005+ # failed
20072006 if (eval {require threads; 1}) {
20082007 $watchdog_thread = ' threads' -> create(sub {
20092008 # Load POSIX if available
@@ -2042,20 +2041,20 @@ ($;$)
20422041 return ;
20432042 }
20442043
2045- # If everything above fails, then just use an alarm timeout
2044+ # If everything above fails, then just use an alarm timeout.
20462045WATCHDOG_VIA_ALARM:
20472046 if (eval { alarm($timeout ); 1; }) {
20482047 # Load POSIX if available
20492048 eval { require POSIX; };
20502049
20512050 # Alarm handler will do the actual 'killing'
20522051 $SIG {' ALRM' } = sub {
2053- select (STDERR ); $| = 1;
2054- _diag($timeout_msg );
2055- POSIX::_exit(1) if (defined (&POSIX::_exit));
2056- my $sig = $is_vms ? ' TERM' : ' KILL' ;
2057- kill ($sig , $pid_to_kill );
2058- };
2052+ select (STDERR ); $| = 1;
2053+ _diag($timeout_msg );
2054+ POSIX::_exit(1) if (defined (&POSIX::_exit));
2055+ my $sig = ( $is_vms ) ? ' TERM' : ' KILL' ;
2056+ kill ($sig , $pid_to_kill );
2057+ };
20592058 }
20602059}
20612060} # End closure
0 commit comments