tools/pygrub: Fix default when out of range
authorIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 29 Jun 2010 15:23:13 +0000 (16:23 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 29 Jun 2010 15:23:13 +0000 (16:23 +0100)
This is the patch to fix pyGrub default value when it's being set out of
range. This patch makes the quiet and interactive mode select the same
default image when the default value for boot entry is out of range,
i.e. when the guest is having wrong configuration in it's boot loader
(like 3 entries with default mistakenly set to 10 etc).

When the boot entry number is being set out of range it falls back to 0
(first entry of boot loader).

Signed-off-by: Michal Novotny <minovotn@redhat.com>
tools/pygrub/src/pygrub

index e52df7b5256ab19f50e4bcc1acd32c066ca0e13e..9c99ba8ce6e5dc9a411cd306718529b79563a407 100644 (file)
@@ -415,6 +415,9 @@ class Grub:
         timeout = int(self.cf.timeout)
 
         self.selected_image = self.cf.default
+        # If the selected (default) image doesn't exist we select the first entry
+        if self.selected_image > len(self.cf.images):
+            self.selected_image = 0
         self.isdone = False
         while not self.isdone:
             self.run_main(timeout)