Moved Say -> Speak::speak
[clearscm.git] / bin / tunnel.pl
index 2ee85f0..86cf076 100755 (executable)
@@ -68,6 +68,7 @@ use Pod::Usage;
 
 use Display;
 use Logger;
+use Speak;
 use Utils;
 
 my $VERSION  = '$Revision: 1.0 $';
@@ -89,27 +90,10 @@ my %opts = (
 
 my ($log, $ssh);
 
-sub Say($) {
-  my ($msg) = @_;
-
-  if (-f "$FindBin::Bin/shh") {
-    $log->msg("Not speaking because we were asked to be quiet - $msg");
-
-    return;
-  } # if
-
-  my ($status, @output) = Execute "/usr/local/bin/gt \"$msg\"";
-
-  $log->err("Unable to speak (Status: $status) - "
-          . join ("\n", @output), $status) if $status;
-
-  return;
-} # Say
-
 sub Report ($;$) {
   my ($msg, $err) = @_;
 
-  Say $msg;
+  speak $msg, $log;
 
   if ($err) {
     $log->err($msg, $err);
@@ -124,6 +108,8 @@ sub interrupt {
    Report "Tunnel killed unexpectedly", 1;
 
    kill 'INT', $ssh->get_master_pid;
+
+   return;
 } # interrupt
 
 sub tunnel() {
@@ -142,6 +128,7 @@ RETRY:
 
   Report("Unable to establish ssh tunnel " . $ssh->error, 1) if $ssh->error;
 
+  # Check to see if address is already in use
   my @lines = <$fh>;
 
   close $fh;
@@ -154,10 +141,13 @@ RETRY:
     my $msg  = 'Ssh tunnel ';
        $msg .= $retryattempts ? 'reestablished' : 'established';
 
-    Say $msg if $opts{announce};
+    speak $msg, $log if $opts{announce};
 
     $log->msg($msg);
 
+    # Reset retry attempts since we reestablished the tunnel
+    $retryattempts = 0 if $retryattempts;
+
     # Wait for master to exit
     waitpid($ssh->get_master_pid, WUNTRACED);
 
@@ -168,6 +158,8 @@ RETRY:
 
     Report 'Ssh tunnel terminated unexpectedly - Attempting restart';
 
+    undef $ssh;
+
     goto RETRY;
   } # if