| 1 | # | ||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||
| 3 | # | ||
| 4 | |||
| 5 | package Rex::Interface::Exec::OpenSSH; | ||
| 6 | |||
| 7 | use v5.14.4; | ||
| 8 | use warnings; | ||
| 9 | |||
| 10 | our $VERSION = '1.16.1'; # VERSION | ||
| 11 | |||
| 12 | use Rex::Helper::SSH2; | ||
| 13 | require Rex::Commands; | ||
| 14 | use Rex::Interface::Exec::SSH; | ||
| 15 | use Rex::Interface::Exec::IOReader; | ||
| 16 | |||
| 17 | use IO::Select; | ||
| 18 | |||
| 19 | use base qw(Rex::Interface::Exec::SSH Rex::Interface::Exec::IOReader); | ||
| 20 | |||
| 21 | sub new { | ||
| 22 | my $that = shift; | ||
| 23 | my $proto = ref($that) || $that; | ||
| 24 | my $self = {@_}; | ||
| 25 | |||
| 26 | bless( $self, $proto ); | ||
| 27 | |||
| 28 | return $self; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub _exec { | ||
| 32 | my ( $self, $exec, $option ) = @_; | ||
| 33 | my ( $out, $err, $pid, $out_fh, $err_fh ); | ||
| 34 | my $ssh = Rex::is_ssh(); | ||
| 35 | |||
| 36 | my $tty = !Rex::Config->get_no_tty; | ||
| 37 | |||
| 38 | ( undef, $out_fh, $err_fh, $pid ) = $ssh->open3( { tty => $tty }, $exec ); | ||
| 39 | |||
| 40 | ( $out, $err ) = $self->io_read( $out_fh, $err_fh, $pid, $option ); | ||
| 41 | |||
| 42 | waitpid( $pid, 0 ) or die($!); | ||
| 43 | if ( $ssh->error || $? ) { | ||
| 44 | |||
| 45 | # we need to bitshift $? so that $? contains the right (and for all | ||
| 46 | # connection methods the same) exit code after a run()/i_run() call. | ||
| 47 | # this is for the user, so that he can query $? in his task. | ||
| 48 | $? >>= 8; | ||
| 49 | } | ||
| 50 | return ( $out, $err ); | ||
| 51 | } | ||
| 52 | |||
| 53 | 1; |