X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FObject-Remote.git;a=blobdiff_plain;f=lib%2FObject%2FRemote%2FConnector%2FLocalSudo.pm;h=044d1060d2a0421b703fd16b336eb2526a32bade;hp=304b3e923b3dcf589100bdc13e9b1b492a3d1186;hb=c824fdf36c659b3b6dbafe23a3021f2b1d6eeb3f;hpb=fbd3b8ecbd2c9004f0e56ff1c0bc30f677a19c62 diff --git a/lib/Object/Remote/Connector/LocalSudo.pm b/lib/Object/Remote/Connector/LocalSudo.pm index 304b3e9..044d106 100644 --- a/lib/Object/Remote/Connector/LocalSudo.pm +++ b/lib/Object/Remote/Connector/LocalSudo.pm @@ -20,13 +20,15 @@ sub _build_password_callback { } } -sub _sudo_perl_command { +has sudo_perl_command => (is => 'lazy'); + +sub _build_sudo_perl_command { my ($self) = @_; return 'sudo', '-S', '-u', $self->target_user, '-p', "[sudo] password please\n", 'perl', '-MPOSIX=dup2', '-e', 'print STDERR "GO\n"; exec(@ARGV);', - $self->_perl_command($self->target_user); + $self->perl_command; } sub _start_perl { @@ -36,7 +38,7 @@ sub _start_perl { my $foreign_stdin, my $foreign_stdout, $sudo_stderr, - $self->_sudo_perl_command(@_) + @{$self->sudo_perl_command} ) or die "open3 failed: $!"; chomp(my $line = <$sudo_stderr>); if ($line eq "GO") { @@ -62,9 +64,16 @@ sub _start_perl { ->watch_io( handle => $sudo_stderr, on_read_ready => sub { - if (sysread($sudo_stderr, my $buf, 1024) > 0) { + #TODO is there a specific reason sysread() and syswrite() aren't + #a part of ::MiniLoop? It's one spot to handle errors and other + #logic involving filehandles + Dlog_debug { "LocalSudo: Preparing to read data from $_" } $sudo_stderr; + if (sysread($sudo_stderr, my $buf, 32768) > 0) { + log_trace { "LocalSudo: successfully read data, printing it to STDERR" }; print STDERR $buf; + log_trace { "LocalSudo: print() to STDERR is done" }; } else { + log_debug { "LocalSudo: received EOF or error on file handle, unwatching it" }; Object::Remote->current_loop ->unwatch_io( handle => $sudo_stderr, @@ -82,7 +91,8 @@ push @Object::Remote::Connection::Guess, sub { for ($_[0]) { # username followed by @ if (defined and !ref and /^ ([^\@]*?) \@ $/x) { - return __PACKAGE__->new(target_user => $1); + shift(@_); + return __PACKAGE__->new(@_, target_user => $1); } } return;