Commit a98e7818 authored by unknown's avatar unknown

kickstart the fake cygwin process in case safe_kill fails

Loop twice over process to shutdown, first handle thise that has been
shutdown and then continue with the ones that have been killed
parent 6a17e468
...@@ -100,6 +100,17 @@ else ...@@ -100,6 +100,17 @@ else
} }
sub _process_alive {
my ($pid)= @_;
return kill(0, $pid) unless IS_WINDOWS;
my @list= split(/,/, `tasklist /FI "PID eq $pid" /NH /FO CSV`);
my $ret_pid= eval($list[1]);
return ($ret_pid == $pid);
}
sub new { sub new {
my $class= shift; my $class= shift;
...@@ -244,6 +255,7 @@ sub shutdown { ...@@ -244,6 +255,7 @@ sub shutdown {
my $shutdown= $proc->{SAFE_SHUTDOWN}; my $shutdown= $proc->{SAFE_SHUTDOWN};
if ($shutdown_timeout > 0 and defined $shutdown){ if ($shutdown_timeout > 0 and defined $shutdown){
$shutdown->(); $shutdown->();
$proc->{WAS_SHUTDOWN}= 1;
} }
else { else {
$proc->start_kill(); $proc->start_kill();
...@@ -252,8 +264,10 @@ sub shutdown { ...@@ -252,8 +264,10 @@ sub shutdown {
my @kill_processes= (); my @kill_processes= ();
# Wait for shutdown_timeout for processes to exit # Wait max shutdown_timeout seconds for those process
# that has been shutdown
foreach my $proc (@processes){ foreach my $proc (@processes){
next unless $proc->{WAS_SHUTDOWN};
my $ret= $proc->wait_one($shutdown_timeout); my $ret= $proc->wait_one($shutdown_timeout);
if ($ret != 0) { if ($ret != 0) {
push(@kill_processes, $proc); push(@kill_processes, $proc);
...@@ -262,20 +276,29 @@ sub shutdown { ...@@ -262,20 +276,29 @@ sub shutdown {
$shutdown_timeout= 0; $shutdown_timeout= 0;
} }
# Wait infinitely for those process
# that has been killed
foreach my $proc (@processes){
next if $proc->{WAS_SHUTDOWN};
my $ret= $proc->wait_one(undef);
if ($ret != 0) {
warn "Wait for killed process failed!";
push(@kill_processes, $proc);
# Try one more time, best option...
}
}
# Return if all servers has exited # Return if all servers has exited
return if (@kill_processes == 0); return if (@kill_processes == 0);
foreach my $proc (@kill_processes){ foreach my $proc (@kill_processes){
if ($proc->start_kill() == 0){ $proc->start_kill();
# Uncertain status, don't wait blocking
# for this process
$proc->{WAIT_ONE_TIMEOUT}= 0;
}
} }
foreach my $proc (@kill_processes){ foreach my $proc (@kill_processes){
$proc->wait_one($proc->{WAIT_ONE_TIMEOUT}); $proc->wait_one(undef);
} }
return; return;
} }
...@@ -289,18 +312,31 @@ sub start_kill { ...@@ -289,18 +312,31 @@ sub start_kill {
_verbose("start_kill: $self"); _verbose("start_kill: $self");
my $ret= 1; my $ret= 1;
if (defined $safe_kill and $self->{SAFE_WINPID}){ my $pid;
if (IS_WINDOWS)
{
die "INTERNAL ERROR: no safe_kill" unless defined $safe_kill;
die "INTERNAL ERROR: no winpid" unless defined $self->{SAFE_WINPID};
# Use my_safe_kill to tell my_safe_process # Use my_safe_kill to tell my_safe_process
# it's time to kill it's child and return # it's time to kill it's child and return
my $pid= $self->{SAFE_WINPID}; $pid= $self->{SAFE_WINPID};
$ret= (system($safe_kill, $pid) >> 8) == 0; $ret= system($safe_kill, $pid) >> 8;
print `tasklist` unless $ret; if (IS_CYGWIN and $ret == 3)
} else { {
my $pid= $self->{SAFE_PID}; print "safe_process is gone, kickstart the fake process\n";
if (kill(15, $self->{SAFE_PID}) != 1){
print STDERR "Failed to kickstart the fake process\n";
}
}
}
else
{
$pid= $self->{SAFE_PID};
die "Can't kill not started process" unless defined $pid; die "Can't kill not started process" unless defined $pid;
$ret= kill(15, $pid); $ret= kill(15, $pid);
} }
print STDERR "$self already killed\n" unless $ret;
return $ret; return $ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment