Skip to content

Commit 51c051d

Browse files
committed
test.pl: Simpler method to cancel watchdog timers
The added END block can simply call watchdog(0), which already has the knowledge to be able to cancel whichever watachdog method is used. Spotted by Tony Cook A comment is added as to why no cancellation is needed of a watchdog implemented by alarm(). Even though a test file should clear every timer before exit, this makes sure it happens.
1 parent fd0ae11 commit 51c051d

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

t/test.pl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,10 @@ sub warning_like {
18381838
{ # Closure
18391839
my $watchdog_process;
18401840
my $watchdog_thread;
1841+
my $watchdog_alarm;
1842+
1843+
# Add END block to terminate and clean up any watchdog
1844+
END { watchdog(0); };
18411845

18421846
sub watchdog ($;$)
18431847
{
@@ -1846,18 +1850,21 @@ ($;$)
18461850
# If cancelling, use the state variables to know which method was used to
18471851
# create the watchdog.
18481852
if ($timeout == 0) {
1853+
1854+
# Is a no-op if no watchdog is currently set
18491855
if ($watchdog_thread) {
18501856
$watchdog_thread->kill('KILL');
1851-
undef $watchdog_thread;
18521857
}
18531858
elsif ($watchdog_process) {
18541859
kill('KILL', $watchdog_process);
1855-
undef $watchdog_process;
18561860
}
1857-
else {
1861+
elsif ($watchdog_alarm) {
18581862
alarm(0);
18591863
}
18601864

1865+
undef $watchdog_thread;
1866+
undef $watchdog_process;
1867+
undef $watchdog_alarm;
18611868
return;
18621869
}
18631870

@@ -1956,24 +1963,14 @@ ($;$)
19561963
goto WATCHDOG_VIA_ALARM;
19571964
}
19581965

1959-
# Add END block to parent to terminate and clean up watchdog
1960-
# process
1961-
eval("END { local \$! = 0; local \$? = 0;
1962-
wait() if kill('KILL', $watchdog_process); };");
19631966
return;
19641967
}
19651968

19661969
# Try using fork() to generate a watchdog process
19671970
undef $watchdog_process;
19681971
eval { $watchdog_process = fork() };
19691972
if (defined($watchdog_process)) {
1970-
if ($watchdog_process) { # Parent process
1971-
# Add END block to parent to terminate and clean up watchdog
1972-
# process
1973-
eval "END { local \$! = 0; local \$? = 0;
1974-
wait() if kill('KILL', $watchdog_process); };";
1975-
return;
1976-
}
1973+
return if $watchdog_process; # Parent process
19771974

19781975
### Watchdog process code
19791976

@@ -2061,6 +2058,8 @@ ($;$)
20612058
my $sig = $is_vms ? 'TERM' : 'KILL';
20622059
kill($sig, $pid_to_kill);
20632060
};
2061+
2062+
$watchdog_alarm = 1;
20642063
}
20652064
}
20662065
} # End closure

0 commit comments

Comments
 (0)