inspector: Don't bomb if no kernels detected.
authorRichard Jones <rjones@trick.home.annexia.org>
Thu, 1 Oct 2009 14:20:14 +0000 (15:20 +0100)
committerRichard Jones <rjones@trick.home.annexia.org>
Thu, 1 Oct 2009 14:20:14 +0000 (15:20 +0100)
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

index 86b1795..dc8847f 100755 (executable)
@@ -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");