Improve process kill on windows
mysql-test/lib/My/SafeProcess.pm: Ifnore Ctrl-C in timer process Don't wait blocking for a preoces where start_kill fails Rewrite sart_kill to return 0 for error and > 1 for sucess mysql-test/lib/My/SafeProcess/safe_process_win.cc: Add missing fflush(stderr) in 'die'
This commit is contained in:
parent
85577e9d2a
commit
7d336347d5
@ -217,7 +217,7 @@ sub timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Child, install signal handlers and sleep for "duration"
|
# Child, install signal handlers and sleep for "duration"
|
||||||
$SIG{INT}= 'DEFAULT';
|
$SIG{INT}= 'IGNORE';
|
||||||
|
|
||||||
$SIG{TERM}= sub {
|
$SIG{TERM}= sub {
|
||||||
#print STDERR "timer $$: woken up, exiting!\n";
|
#print STDERR "timer $$: woken up, exiting!\n";
|
||||||
@ -281,11 +281,15 @@ sub shutdown {
|
|||||||
return if (@kill_processes == 0);
|
return if (@kill_processes == 0);
|
||||||
|
|
||||||
foreach my $proc (@kill_processes){
|
foreach my $proc (@kill_processes){
|
||||||
$proc->start_kill();
|
if ($proc->start_kill() == 0){
|
||||||
|
# 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($proc->{WAIT_ONE_TIMEOUT});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -298,20 +302,20 @@ sub start_kill {
|
|||||||
my ($self)= @_;
|
my ($self)= @_;
|
||||||
croak "usage: \$safe_proc->start_kill()" unless (@_ == 1 and ref $self);
|
croak "usage: \$safe_proc->start_kill()" unless (@_ == 1 and ref $self);
|
||||||
#print "start_kill $self\n";
|
#print "start_kill $self\n";
|
||||||
|
my $ret= 1;
|
||||||
|
|
||||||
if (defined $safe_kill and $self->{SAFE_WINPID}){
|
if (defined $safe_kill and $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};
|
my $pid= $self->{SAFE_WINPID};
|
||||||
my $ret= system($safe_kill, $pid);
|
$ret= (system($safe_kill, $pid) >> 8) == 0;
|
||||||
#print STDERR "start_kill, safe_killed $pid, ret: $ret\n";
|
|
||||||
} else {
|
} else {
|
||||||
my $pid= $self->{SAFE_PID};
|
my $pid= $self->{SAFE_PID};
|
||||||
die "Can't kill not started process" unless defined $pid;
|
die "Can't kill not started process" unless defined $pid;
|
||||||
my $ret= kill(15, $pid);
|
$ret= kill(15, $pid);
|
||||||
#print STDERR "start_kill, sent signal 15 to $pid, ret: $ret\n";
|
|
||||||
}
|
}
|
||||||
return 1;
|
print STDERR "$self already killed\n" unless $ret;
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -323,8 +327,10 @@ sub kill {
|
|||||||
my ($self)= @_;
|
my ($self)= @_;
|
||||||
croak "usage: \$safe_proc->kill()" unless (@_ == 1 and ref $self);
|
croak "usage: \$safe_proc->kill()" unless (@_ == 1 and ref $self);
|
||||||
|
|
||||||
$self->start_kill();
|
if ($self->start_kill())
|
||||||
$self->wait_one();
|
{
|
||||||
|
$self->wait_one();
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ static void die(const char* fmt, ...)
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
if (int last_err= GetLastError())
|
if (int last_err= GetLastError())
|
||||||
fprintf(stderr, "error: %d, %s\n", last_err, strerror(last_err));
|
fprintf(stderr, "error: %d, %s\n", last_err, strerror(last_err));
|
||||||
|
fflush(stderr);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user