fix compile error and reap orphans
This commit is contained in:
parent
4f5bc24104
commit
103181da19
@ -509,7 +509,8 @@ sub _stop_child_collectors {
|
|||||||
sub _reap_orphaned_collectors {
|
sub _reap_orphaned_collectors {
|
||||||
debug(__LINE__, "Scanning for orphaned collector processes from a previous worker");
|
debug(__LINE__, "Scanning for orphaned collector processes from a previous worker");
|
||||||
|
|
||||||
unless (opendir(my $dh, '/proc')) {
|
my $dh;
|
||||||
|
unless (opendir($dh, '/proc')) {
|
||||||
debug(__LINE__, "Failed to open /proc: $!");
|
debug(__LINE__, "Failed to open /proc: $!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -546,19 +547,22 @@ sub _reap_orphaned_collectors {
|
|||||||
debug(__LINE__, "Sent SIGTERM to orphaned collector PID $pid");
|
debug(__LINE__, "Sent SIGTERM to orphaned collector PID $pid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Orphans are already zombies as soon as init reaps them, and kill(0,...)
|
||||||
|
# keeps reporting a zombie's PID as present - use is_process_alive() so we
|
||||||
|
# don't spin the full timeout (or send a pointless KILL) on a dead PID.
|
||||||
my $timeout = 2;
|
my $timeout = 2;
|
||||||
my $start = time();
|
my $start = time();
|
||||||
while (time() - $start < $timeout) {
|
while (time() - $start < $timeout) {
|
||||||
my $any_alive = 0;
|
my $any_alive = 0;
|
||||||
foreach my $pid (@orphans) {
|
foreach my $pid (@orphans) {
|
||||||
if (kill(0, $pid)) { $any_alive = 1; last; }
|
if (is_process_alive($pid)) { $any_alive = 1; last; }
|
||||||
}
|
}
|
||||||
last unless $any_alive;
|
last unless $any_alive;
|
||||||
select(undef, undef, undef, 0.1);
|
select(undef, undef, undef, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $pid (@orphans) {
|
foreach my $pid (@orphans) {
|
||||||
if (kill(0, $pid)) {
|
if (is_process_alive($pid)) {
|
||||||
debug(__LINE__, "Force killing orphaned collector process $pid");
|
debug(__LINE__, "Force killing orphaned collector process $pid");
|
||||||
kill('KILL', $pid);
|
kill('KILL', $pid);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user