Commit 2d238792 authored by Magnus Svensson's avatar Magnus Svensson

BUG#38559 Annoying cygwin problem fixed by resolving pid->winpid before kill...

BUG#38559 Annoying cygwin problem fixed by resolving  pid->winpid before kill instead of just after fork
parent fc6a7def
...@@ -148,7 +148,7 @@ sub new { ...@@ -148,7 +148,7 @@ sub new {
print "### safe_path: ", $safe_path, " ", join(" ", @safe_args), "\n" print "### safe_path: ", $safe_path, " ", join(" ", @safe_args), "\n"
if $verbose > 1; if $verbose > 1;
my ($pid, $winpid)= create_process( my $pid= create_process(
path => $safe_path, path => $safe_path,
input => $input, input => $input,
output => $output, output => $output,
...@@ -161,7 +161,7 @@ sub new { ...@@ -161,7 +161,7 @@ sub new {
my $proc= bless my $proc= bless
({ ({
SAFE_PID => $pid, SAFE_PID => $pid,
SAFE_WINPID => $winpid, SAFE_WINPID => $pid, # Inidicates this is always a real process
SAFE_NAME => $name, SAFE_NAME => $name,
SAFE_SHUTDOWN => $shutdown, SAFE_SHUTDOWN => $shutdown,
PARENT => $$, PARENT => $$,
...@@ -296,6 +296,18 @@ sub shutdown { ...@@ -296,6 +296,18 @@ sub shutdown {
} }
sub _winpid ($) {
my ($pid)= @_;
# In win32 perl, the pid is already the winpid
return $pid unless IS_CYGWIN;
# In cygwin, the pid is the pseudo process ->
# get the real winpid of my_safe_process
return Cygwin::pid_to_winpid($pid);
}
# #
# Tell the process to die as fast as possible # Tell the process to die as fast as possible
# #
...@@ -305,22 +317,24 @@ sub start_kill { ...@@ -305,22 +317,24 @@ sub start_kill {
_verbose("start_kill: $self"); _verbose("start_kill: $self");
my $ret= 1; my $ret= 1;
my $pid; my $pid= $self->{SAFE_PID};
die "INTERNAL ERROR: no pid" unless defined $pid;
if (IS_WINDOWS and defined $self->{SAFE_WINPID}) if (IS_WINDOWS and defined $self->{SAFE_WINPID})
{ {
die "INTERNAL ERROR: no safe_kill" unless defined $safe_kill; 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 my $winpid= _winpid($pid);
# it's time to kill it's child and return $ret= system($safe_kill, $winpid) >> 8;
$pid= $self->{SAFE_WINPID};
$ret= system($safe_kill, $pid) >> 8; if ($ret == 3){
if (IS_CYGWIN and $ret == 3) print "Couldn't open the winpid: $winpid ",
{ "for pid: $pid, try one more time\n";
print "safe_process is gone, kickstart the fake process, $self\n"; sleep(1);
if (kill(15, $self->{SAFE_PID}) != 1){ $winpid= _winpid($pid);
print STDERR "Failed to kickstart the fake process\n"; $ret= system($safe_kill, $winpid) >> 8;
} print "Couldn't open the winpid: $winpid ",
"for pid: $pid, continue and see what happens...\n";
} }
} }
else else
......
...@@ -33,30 +33,6 @@ use base qw(Exporter); ...@@ -33,30 +33,6 @@ use base qw(Exporter);
our @EXPORT= qw(create_process); our @EXPORT= qw(create_process);
sub winpid {
my ($pid)= @_;
return undef unless $^O eq "cygwin";
# The child get a new winpid when the exec takes
# place, wait for that to happen
my $winpid;
my $delay= 0;
do
{
# Yield to the child
select(undef, undef, undef, $delay);
# Increase the delay slightly for each loop
$delay += 0.000001;
$winpid= Cygwin::pid_to_winpid($pid);
} until ($winpid != $pid);
return $winpid;
}
# #
# safe_fork # safe_fork
...@@ -179,7 +155,7 @@ sub create_process { ...@@ -179,7 +155,7 @@ sub create_process {
or croak("unable to reestablish STDIN"); or croak("unable to reestablish STDIN");
#printf STDERR "stdin %d, stdout %d, stderr %d\n", #printf STDERR "stdin %d, stdout %d, stderr %d\n",
# fileno STDIN, fileno STDOUT, fileno STDERR; # fileno STDIN, fileno STDOUT, fileno STDERR;
return wantarray ? ($pid, $pid) : $pid; return $pid;
} }
...@@ -190,7 +166,7 @@ sub create_process { ...@@ -190,7 +166,7 @@ sub create_process {
# Parent # Parent
$pipe->reader(); $pipe->reader();
my $line= <$pipe>; # Wait for child to say it's ready my $line= <$pipe>; # Wait for child to say it's ready
return wantarray ? ($pid, winpid($pid)) : $pid; return $pid;
} }
$SIG{INT}= 'DEFAULT'; $SIG{INT}= 'DEFAULT';
......
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