[2/6] testbot/TestAgent: Retrieve the netcat error when the connection breaks.

Francois Gouget fgouget at codeweavers.com
Mon Feb 25 10:32:50 CST 2013


It may provide important clues as to what went wrong, especially when trying to connect.
---

In particular, instead of the dreaded 'could not get the protocol 
version spoken by the server: got a premature network EOF' error message 
we should get stuff like 'netcat: getaddrinfo: Name or service not 
known' which is much more informative.


 testbot/lib/WineTestBot/TestAgent.pm |   31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/testbot/lib/WineTestBot/TestAgent.pm b/testbot/lib/WineTestBot/TestAgent.pm
index 1f52818..0e5eb4d 100644
--- a/testbot/lib/WineTestBot/TestAgent.pm
+++ b/testbot/lib/WineTestBot/TestAgent.pm
@@ -88,6 +88,7 @@ sub Disconnect($)
     # which will avoid undue delays.
     $self->{ssh}->disconnect();
     $self->{ssh} = undef;
+    $self->{nc} = undef;
   }
   if ($self->{sshfd})
   {
@@ -148,7 +149,29 @@ sub _SetError($$$)
     $self->{err} = $Msg;
 
     # And disconnect on fatal errors since the connection is unusable anyway
-    $self->Disconnect() if ($Level == $FATAL);
+    if ($Level == $FATAL)
+    {
+      if ($self->{ssh})
+      {
+        # Try to capture the netcat exit code and error message as
+        # they may provide important clues as to what went wrong
+        my $rc = $self->{fd}->exit_status();
+        if ($rc)
+        {
+          my $ncerr;
+          eval
+          {
+            alarm(2);
+            $self->{fd}->read($ncerr, 1024, 1);
+            alarm(0);
+          };
+          $ncerr = $rc if (!$ncerr);
+          $ncerr = "the \"$self->{nc}\" command returned $ncerr";
+          $self->{err} = $self->{agentversion} ? "$self->{err}\n$ncerr" : $ncerr;
+        }
+      }
+      $self->Disconnect();
+    }
   }
   elsif (!$self->{err})
   {
@@ -851,7 +874,9 @@ sub _Connect($)
 
     # Use netcat to forward the connection from the SSH server to the TestAgent
     # server. Note that we won't know about netcat errors at this point.
-    if (!$self->{fd}->exec("nc -q0 '$self->{agenthost}' '$self->{agentport}'"))
+    $self->{nc} = "nc -q0 '$self->{agenthost}' '$self->{agentport}'";
+    debug("Tunneling command: $self->{nc}\n");
+    if (!$self->{fd}->exec($self->{nc}))
     {
       $self->_SetError($FATAL, "Unable to start netcat: " . $self->_ssherror());
       return undef;
@@ -864,7 +889,7 @@ sub _Connect($)
   if (!defined $self->{agentversion})
   {
     # We have already been disconnected at this point
-    $self->{err} = "Unable to get the protocol version spoken by the server: $self->{err}";
+    debug("could not get the protocol version spoken by the server\n");
     return undef;
   }
 
-- 
1.7.10.4




More information about the wine-patches mailing list