From: Tyler Riddle Date: Fri, 28 Sep 2012 21:59:53 +0000 (-0700) Subject: first attempt at fixing ssh/sh escaping problem with perl_command - works but isn... X-Git-Tag: v0.003001_01~106 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=commitdiff_plain;h=b9baacc29444767f88abdbca93f65c8bd5e5a676 first attempt at fixing ssh/sh escaping problem with perl_command - works but isn't the right way to do it --- diff --git a/lib/Object/Remote/Connector/SSH.pm b/lib/Object/Remote/Connector/SSH.pm index bb0b869..fcfb445 100644 --- a/lib/Object/Remote/Connector/SSH.pm +++ b/lib/Object/Remote/Connector/SSH.pm @@ -17,12 +17,24 @@ has ssh_command => (is => 'ro', default => sub { 'ssh' }); #TODO properly integrate if this works BEGIN { $ENV{TERM} = 'dumb'; } +sub _escape_shell_arg { + my ($self, $str) = (@_); + $str =~ s/((?:^|[^\\])(?:\\\\)*)'/$1\\'/g; + return "$str"; +} + + sub _build_ssh_perl_command { my ($self) = @_; + my $perl_command = join('', @{$self->perl_command}); + + #TODO non-trivial to escape properly for ssh and shell + #this "works" but is not right, needs to be replaced + #after testing return [ do { my $c = $self->ssh_command; ref($c) ? @$c : $c }, @{$self->ssh_options}, $self->ssh_to, - @{$self->perl_command} + $self->_escape_shell_arg($perl_command), ]; } diff --git a/lib/Object/Remote/Role/Connector/PerlInterpreter.pm b/lib/Object/Remote/Role/Connector/PerlInterpreter.pm index afbf8bf..31e13e2 100644 --- a/lib/Object/Remote/Role/Connector/PerlInterpreter.pm +++ b/lib/Object/Remote/Role/Connector/PerlInterpreter.pm @@ -34,8 +34,8 @@ has watchdog_timeout => ( is => 'ro', required => 1, default => sub { 0 } ); #ulimit of ~500 megs of v-ram #TODO only works with ssh with quotes but only works locally #with out quotes -#sub _build_perl_command { [ 'sh', '-c', '"ulimit -v 200000; nice -n 15 perl -"' ] } -sub _build_perl_command { [ 'perl', '-' ] } +sub _build_perl_command {[ 'sh -c "ulimit -v 200000; nice -n 15 perl -"' ] } +#sub _build_perl_command { [ 'perl', '-' ] } #sub _build_perl_command { [ 'cat' ] } around connect => sub { @@ -156,7 +156,7 @@ sub _setup_watchdog_reset { Dlog_trace { "Creating Watchdog management timer for connection id $_" } $conn->_id; $timer_id = Object::Remote->current_loop->watch_time( - every => $self->watchdog_timeout / 5, + every => $self->watchdog_timeout / 3, code => sub { unless(defined($conn)) { log_trace { "Weak reference to connection in Watchdog was lost, terminating update timer $timer_id" };