提交 6b3e8b94 编写于 作者: A Andy Polyakov

TLSProxy/Proxy.pm: handle -1 as return value from waitpid.

On rare occasion 's_server | perl -ne print' can complete before
corresponding waitpid, which on Windows can results in -1 return
value. This is not an error, don't treat it like one. Collect
even return value from s_server.
Reviewed-by: NBernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: NRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5907)
上级 362ff3c3
...@@ -243,7 +243,8 @@ sub start ...@@ -243,7 +243,8 @@ sub start
if ($self->{server_port} == 0) { if ($self->{server_port} == 0) {
# This actually means that s_server exited, because otherwise # This actually means that s_server exited, because otherwise
# we would still searching for ACCEPT... # we would still searching for ACCEPT...
die "no ACCEPT detected in '$execcmd' output\n"; waitpid($pid, 0);
die "no ACCEPT detected in '$execcmd' output: $?\n";
} }
# Just make sure everything else is simply printed [as separate lines]. # Just make sure everything else is simply printed [as separate lines].
...@@ -255,6 +256,7 @@ sub start ...@@ -255,6 +256,7 @@ sub start
if (eval { require Win32::Process; 1; }) { if (eval { require Win32::Process; 1; }) {
if (Win32::Process::Create(my $h, $^X, "perl -ne print", 0, 0, ".")) { if (Win32::Process::Create(my $h, $^X, "perl -ne print", 0, 0, ".")) {
$pid = $h->GetProcessID(); $pid = $h->GetProcessID();
$self->{proc_handle} = $h; # hold handle till next round [or exit]
} else { } else {
$error = Win32::FormatMessage(Win32::GetLastError()); $error = Win32::FormatMessage(Win32::GetLastError());
} }
...@@ -412,11 +414,19 @@ sub clientstart ...@@ -412,11 +414,19 @@ sub clientstart
my $pid; my $pid;
if (--$self->{serverconnects} == 0) { if (--$self->{serverconnects} == 0) {
$pid = $self->{serverpid}; $pid = $self->{serverpid};
die "serverpid is zero\n" if $pid == 0; print "Waiting for 'perl -ne print' process to close: $pid...\n";
print "Waiting for server process to close: $pid...\n"; $pid = waitpid($pid, 0);
# recall that we wait on process that buffers server's output if ($pid > 0) {
die "exit code $? from 'perl -ne print' process\n" if $? != 0;
} elsif ($pid == 0) {
kill(3, $self->{real_serverpid});
die "lost control over $self->{serverpid}?";
}
$pid = $self->{real_serverpid};
print "Waiting for s_server process to close: $pid...\n";
# it's done already, just collect the exit code [and reap]...
waitpid($pid, 0); waitpid($pid, 0);
die "exit code $? from server process\n" if $? != 0; die "exit code $? from s_server process\n" if $? != 0;
} else { } else {
# It's a bit counter-intuitive spot to make next connection to # It's a bit counter-intuitive spot to make next connection to
# the s_server. Rationale is that established connection works # the s_server. Rationale is that established connection works
...@@ -425,7 +435,6 @@ sub clientstart ...@@ -425,7 +435,6 @@ sub clientstart
$self->connect_to_server(); $self->connect_to_server();
} }
$pid = $self->{clientpid}; $pid = $self->{clientpid};
die "clientpid is zero\n" if $pid == 0;
print "Waiting for client process to close: $pid...\n"; print "Waiting for client process to close: $pid...\n";
waitpid($pid, 0); waitpid($pid, 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册