about summary refs log tree commit diff
path: root/perl/lib/Nix/SSH.pm
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-11-10T15·03+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-11-10T15·03+0100
commitd436e44ae3a7fc310660db0cc3078a9c1c9318e4 (patch)
tree1c635a6edbf52a72bef012dffc4bda18d75aa631 /perl/lib/Nix/SSH.pm
parent087581a6428920f781008815cac4bec6a739a8aa (diff)
SSH.pm: Print a friendlier message if connecting fails
"got EOF while expecting 8 bytes from remote side" is not very
helpful.
Diffstat (limited to 'perl/lib/Nix/SSH.pm')
-rw-r--r--perl/lib/Nix/SSH.pm15
1 files changed, 11 insertions, 4 deletions
diff --git a/perl/lib/Nix/SSH.pm b/perl/lib/Nix/SSH.pm
index 9e0c10beb0e0..95393d881450 100644
--- a/perl/lib/Nix/SSH.pm
+++ b/perl/lib/Nix/SSH.pm
@@ -1,5 +1,6 @@
 package Nix::SSH;
 
+use utf8;
 use strict;
 use File::Temp qw(tempdir);
 use IPC::Open2;
@@ -89,10 +90,16 @@ sub connectToRemoteNix {
     my $pid = open2($from, $to, "exec ssh -x -a $sshHost @globalSshOpts @{$sshOpts} nix-store --serve --write $extraFlags");
 
     # Do the handshake.
-    my $SERVE_MAGIC_1 = 0x390c9deb; # FIXME
-    my $clientVersion = 0x200;
-    syswrite($to, pack("L<x4L<x4", $SERVE_MAGIC_1, $clientVersion)) or die;
-    die "did not get valid handshake from remote host\n" if readInt($from) != 0x5452eecb;
+    my $magic;
+    eval {
+        my $SERVE_MAGIC_1 = 0x390c9deb; # FIXME
+        my $clientVersion = 0x200;
+        syswrite($to, pack("L<x4L<x4", $SERVE_MAGIC_1, $clientVersion)) or die;
+        $magic = readInt($from);
+    };
+    die "unable to connect to ‘$sshHost’\n" if $@;
+    die "did not get valid handshake from remote host\n" if $magic  != 0x5452eecb;
+
     my $serverVersion = readInt($from);
     die "unsupported server version\n" if $serverVersion < 0x200 || $serverVersion >= 0x300;