X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=bin%2Ftunnel.pl;h=084f661c7711922419d0fc3a386bfc0403c31080;hb=fc0e2c7f3fce9e64608d0aa13399d62f24000784;hp=9472e88e5e510afa9c79775ebbc2fdb2df6fb4a5;hpb=89be03cdf0fd811112da15b47d710f7bc3a00e74;p=clearscm.git diff --git a/bin/tunnel.pl b/bin/tunnel.pl index 9472e88..084f661 100755 --- a/bin/tunnel.pl +++ b/bin/tunnel.pl @@ -71,6 +71,8 @@ use Logger; use Speak; use Utils; +local $0 = $FindBin::Script; + my $VERSION = '$Revision: 1.0 $'; ($VERSION) = ($VERSION =~ /\$Revision: (.*) /); @@ -85,9 +87,13 @@ my %opts = ( port2 => 25, remotehost => 'defaria.com', maxretries => 3, - daemon => 1, ); +# Perlcritic complains if $DB::OUT is used only once. +no warnings; +$opts{daemon} = 1 unless defined $DB::OUT; +use warnings; + my ($log, $ssh); sub Report ($;$) { @@ -120,7 +126,7 @@ sub tunnel() { RETRY: my ($fh, $filename) = tempfile; - my $ssh = Net::OpenSSH->new( + $ssh = Net::OpenSSH->new( $opts{remotehost}, master_opts => $tunnelStr, default_stderr_file => $filename @@ -135,7 +141,7 @@ RETRY: unlink $filename; - if (grep /address already in use/i, @lines) { + if (grep { /address already in use/i } @lines) { Report 'Unable to start tunnel - Address already in use', 1; } else { my $msg = 'Ssh tunnel '; @@ -154,10 +160,6 @@ RETRY: Report("Ssh tunnel terminated unexpectedly - Maximum retry count hit ($opts{maxretries}) - giving up", 1) if $retryattempts++ >= $opts{maxretries}; - $opts{announce} = $retryattempts; - - Report 'Ssh tunnel terminated unexpectedly - Attempting restart'; - undef $ssh; goto RETRY; @@ -183,11 +185,6 @@ GetOptions ( 'append', ) || Usage; -# Turn off daemon mode if we are in the Perl debugger; -no warnings; # Ignore warning about used only once $DB::OUT when not in debugger -$opts{daemon} = 0 if defined $DB::OUT; -use warnings; - $log = Logger->new( path => '/var/local/log', name => "$Logger::me", @@ -199,11 +196,6 @@ $log->msg("$FindBin::Script v$VERSION"); $SIG{INT} = $SIG{TERM} = \&interrupt; -if ($opts{daemon}) { - # Perl complains if we reference $DB::OUT only once - no warnings; - EnterDaemonMode unless defined $DB::OUT or get_debug; - use warnings; -} # if +EnterDaemonMode unless $opts{daemon} and get_debug; tunnel;