summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-08-11 20:52:28 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-08-11 20:53:00 +0100
commit2c046c0d6fb2faccc2b2d5596d0af1c8d043eb76 (patch)
tree20a50fcaa380812e93ef748d7ad70932e255f231
parent2295b09f259ece053f1370f7527d01705976732a (diff)
downloadlibguestfs-2c046c0d6fb2faccc2b2d5596d0af1c8d043eb76.tar.gz
libguestfs-2c046c0d6fb2faccc2b2d5596d0af1c8d043eb76.tar.xz
libguestfs-2c046c0d6fb2faccc2b2d5596d0af1c8d043eb76.zip
virt-make-fs: Don't display output of 'qemu-img' except on error path.
-rwxr-xr-xtools/virt-make-fs31
1 files changed, 27 insertions, 4 deletions
diff --git a/tools/virt-make-fs b/tools/virt-make-fs
index 8def5e3a..281c92c1 100755
--- a/tools/virt-make-fs
+++ b/tools/virt-make-fs
@@ -24,11 +24,12 @@ use Sys::Guestfs::Lib qw(feature_available);
use Pod::Usage;
use Getopt::Long;
-use File::Temp qw(tempdir);
+use File::Temp qw(tempfile tempdir);
use POSIX qw(mkfifo floor);
use Data::Dumper;
use String::ShellQuote qw(shell_quote);
use Locale::TextDomain 'libguestfs';
+use Fcntl qw(SEEK_SET);
=encoding utf8
@@ -417,14 +418,36 @@ if (!defined $size) {
$size = int ($size);
# Create the output disk.
-# Take the unusual step of invoking qemu-img here.
+#
+# Use qemu-img so we can control the output format, but capture any
+# output temporarily and only display it if the command fails.
my @cmd = ("qemu-img", "create", "-f", $format, $output, $size);
if ($debug) {
print STDERR ("running: ", join (" ", @cmd), "\n");
}
-system (@cmd) == 0 or
- die __"qemu-img create: failed to create disk image, see earlier error messages\n";
+
+{
+ my $tmpfh = tempfile ();
+ my ($r, $oldout, $olderr);
+
+ open $oldout, ">&STDOUT" or die __"cannot dup STDOUT";
+ open $olderr, ">&STDERR" or die __"cannot dup STDERR";
+ close STDOUT;
+ close STDERR;
+ open STDOUT, ">&", \$tmpfh or die __"cannot redirect STDOUT";
+ open STDERR, ">&", \$tmpfh or die __"cannot redirect STDERR";
+ $r = system (@cmd);
+ open STDOUT, ">&", $oldout or die __"cannot restore STDOUT";
+ open STDERR, ">&", $olderr or die __"cannot restore STDERR";
+
+ unless ($r == 0) {
+ print STDERR __"qemu-img create: failed to create disk image:\n";
+ seek $tmpfh, 0, SEEK_SET;
+ print STDERR $_ while <$tmpfh>;
+ die "\n";
+ }
+}
eval {
print STDERR "starting libguestfs ...\n" if $debug;