From: Ian Jackson Subject: [OSSTEST PATCH 3/7] TestSupport: Honour $stdin fh argument to cmd, tcmd and tcmdex Date: Tue, 29 Sep 2015 14:37:23 +0100 Message-ID: <1443533847-16987-4-git-send-email-ian.jackson@eu.citrix.com> References: <1443533847-16987-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Zgv6D-0002r1-FA for xen-devel@lists.xenproject.org; Tue, 29 Sep 2015 13:37:41 +0000 In-Reply-To: <1443533847-16987-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org These are internal functions, so the change is entirely within TestSupport. All the call sites are adjusted to pass undef so there is no functional change. Signed-off-by: Ian Jackson --- Osstest/TestSupport.pm | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm index 7b9d815..91829a0 100644 --- a/Osstest/TestSupport.pm +++ b/Osstest/TestSupport.pm @@ -323,9 +323,13 @@ sub target_adjust_timeout ($$) { #---------- running commands eg on targets ---------- sub cmd { - my ($timeout,$stdout,@cmd) = @_; + my ($timeout,$stdin,$stdout,@cmd) = @_; my $child= fork; die $! unless defined $child; if (!$child) { + if (defined $stdin) { + open STDIN, '<&', $stdin + or die "STDIN $stdin $cmd[0] $!"; + } if (defined $stdout) { open STDOUT, '>&', $stdout or die "STDOUT $stdout $cmd[0] $!"; @@ -395,19 +399,20 @@ sub sshopts () { } sub tcmdex { - my ($timeout,$stdout,$cmd,$optsref,@args) = @_; + my ($timeout,$stdin,$stdout,$cmd,$optsref,@args) = @_; logm("executing $cmd ... @args"); # We use timeout(1) as a backstop, in case $cmd doesn't die. We # need $cmd to die because we won't release the resources we own # until all of our children are dead. - my $r= cmd($timeout,$stdout, 'timeout',$timeout+30, $cmd,@$optsref,@args); + my $r= cmd($timeout,$stdin,$stdout, + 'timeout',$timeout+30, $cmd,@$optsref,@args); $r and die "status $r"; } sub tgetfileex { my ($ruser, $ho,$timeout, $rsrc,$ldst) = @_; unlink $ldst or $!==&ENOENT or die "$ldst $!"; - tcmdex($timeout,undef, + tcmdex($timeout,undef,undef, 'scp', sshopts(), sshuho($ruser,$ho).":$rsrc", $ldst); } @@ -424,12 +429,12 @@ sub tputfileex { my ($ruser, $ho,$timeout, $lsrc,$rdst, $rsync) = @_; my @args= ($lsrc, sshuho($ruser,$ho).":$rdst"); if (!defined $rsync) { - tcmdex($timeout,undef, + tcmdex($timeout,undef,undef, 'scp', sshopts(), @args); } else { unshift @args, $rsync if length $rsync; - tcmdex($timeout,undef, + tcmdex($timeout,undef,undef, 'rsync', [ '-e', 'ssh '.join(' ',@{ sshopts() }) ], @args); } @@ -625,19 +630,19 @@ sub target_await_down ($$) { } sub tcmd { # $tcmd will be put between '' but not escaped - my ($stdout,$user,$ho,$tcmd,$timeout,$extrasshopts) = @_; + my ($stdin,$stdout,$user,$ho,$tcmd,$timeout,$extrasshopts) = @_; $timeout=30 if !defined $timeout; target_adjust_timeout($ho,\$timeout); - tcmdex($timeout,$stdout, + tcmdex($timeout,$stdin,$stdout, 'ssh', sshopts(), @{ $extrasshopts || [] }, sshuho($user,$ho), $tcmd); } -sub target_cmd ($$;$$) { tcmd(undef,'osstest',@_); } -sub target_cmd_root ($$;$$) { tcmd(undef,'root',@_); } +sub target_cmd ($$;$$) { tcmd(undef,undef,'osstest',@_); } +sub target_cmd_root ($$;$$) { tcmd(undef,undef,'root',@_); } sub tcmdout { my $stdout= IO::File::new_tmpfile(); - tcmd($stdout,@_); + tcmd(undef,$stdout,@_); $stdout->seek(0,0) or die "$stdout $!"; my $r; { local ($/) = undef; -- 1.7.10.4