Richard W.M. Jones
2009-Oct-01 14:24 UTC
[Libguestfs] [PATCH] inspector: Don't bomb if no kernels detected.
This is a partial fix for https://bugzilla.redhat.com/show_bug.cgi?id=526717 Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html -------------- next part -------------->From 5021b2efea92c021c04812056149485ac4803e9c Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at trick.home.annexia.org> Date: Thu, 1 Oct 2009 15:20:14 +0100 Subject: [PATCH 1/2] inspector: Don't bomb if no kernels detected. If $os->{kernels} wasn't defined, virt-inspector would exit with an error, leaving partial XML output. Change the code so it doesn't die in this case, instead just leaves out the <kernels> section. --- inspector/virt-inspector | 34 ++++++++++++++++++---------------- 1 files changed, 18 insertions(+), 16 deletions(-) diff --git a/inspector/virt-inspector b/inspector/virt-inspector index 86b1795..dc8847f 100755 --- a/inspector/virt-inspector +++ b/inspector/virt-inspector @@ -550,23 +550,25 @@ sub output_xml_os $xml->endTag("boot"); } - $xml->startTag("kernels"); - my @kernels = @{$os->{kernels}}; - foreach (@kernels) { - $xml->startTag("kernel", - "version" => $_->{version}, - "arch" => $_->{arch}); - $xml->startTag("modules"); - my @modules = @{$_->{modules}}; - foreach (@modules) { - $xml->dataElement("module", $_); - } - $xml->endTag("modules"); - $xml->dataElement("path", $_->{path}) if(defined($_->{path})); - $xml->dataElement("package", $_->{package}) if(defined($_->{package})); - $xml->endTag("kernel"); + if ($os->{kernels}) { + $xml->startTag("kernels"); + my @kernels = @{$os->{kernels}}; + foreach (@kernels) { + $xml->startTag("kernel", + "version" => $_->{version}, + "arch" => $_->{arch}); + $xml->startTag("modules"); + my @modules = @{$_->{modules}}; + foreach (@modules) { + $xml->dataElement("module", $_); + } + $xml->endTag("modules"); + $xml->dataElement("path", $_->{path}) if(defined($_->{path})); + $xml->dataElement("package", $_->{package}) if(defined($_->{package})); + $xml->endTag("kernel"); + } + $xml->endTag("kernels"); } - $xml->endTag("kernels"); if (exists $os->{root}->{registry}) { $xml->startTag("windowsregistryentries"); -- 1.6.2.5
Jim Meyering
2009-Oct-01 15:49 UTC
[Libguestfs] [PATCH] inspector: Don't bomb if no kernels detected.
Richard W.M. Jones wrote:> This is a partial fix for > https://bugzilla.redhat.com/show_bug.cgi?id=526717...> Subject: [PATCH 1/2] inspector: Don't bomb if no kernels detected. > > If $os->{kernels} wasn't defined, virt-inspector would exit with > an error, leaving partial XML output. > > Change the code so it doesn't die in this case, instead just > leaves out the <kernels> section. > --- > inspector/virt-inspector | 34 ++++++++++++++++++---------------- > 1 files changed, 18 insertions(+), 16 deletions(-) > > diff --git a/inspector/virt-inspector b/inspector/virt-inspector > index 86b1795..dc8847f 100755 > --- a/inspector/virt-inspector > +++ b/inspector/virt-inspector > @@ -550,23 +550,25 @@ sub output_xml_os > $xml->endTag("boot"); > } > > - $xml->startTag("kernels"); > - my @kernels = @{$os->{kernels}}; > - foreach (@kernels) { > - $xml->startTag("kernel", > - "version" => $_->{version}, > - "arch" => $_->{arch}); > - $xml->startTag("modules"); > - my @modules = @{$_->{modules}}; > - foreach (@modules) { > - $xml->dataElement("module", $_); > - } > - $xml->endTag("modules"); > - $xml->dataElement("path", $_->{path}) if(defined($_->{path})); > - $xml->dataElement("package", $_->{package}) if(defined($_->{package})); > - $xml->endTag("kernel"); > + if ($os->{kernels}) {...<indented-code-elided>...> + $xml->endTag("kernels"); > } > - $xml->endTag("kernels"); > > if (exists $os->{root}->{registry}) { > $xml->startTag("windowsregistryentries");ACK. That will definitely result in better output.