]> git.ozlabs.org Git - petitboot/commitdiff
discover/grub2: Allow using title for default even if id was defined
authorJavier Martinez Canillas <javierm@redhat.com>
Thu, 20 Jun 2019 16:09:55 +0000 (18:09 +0200)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Fri, 21 Jun 2019 03:42:15 +0000 (13:42 +1000)
A default menu entry can be chosen using any of the following attributes:
index, title or id (if the entry was defined with the --id option).

But Petitboot doesn't honor this correctly and only compares the default
with the menu entry title if the entry doesn't have an id defined. This
is wrong since an index or title can be used even if an id was defined.

This issue wasn't covered by the test that sets a default using a title
because the menu entries didn't have an id defined. Add an id to them.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/grub2/script.c
test/parser/test-grub2-default-multiword.c

index 902df90045994fb6daaa0b1effc39adc238ee289..c910bf8bc1a28bf86901459b11d7a99ad059bc35 100644 (file)
@@ -117,12 +117,10 @@ static bool option_is_default(struct grub2_script *script,
        if (end != var && *end == '\0')
                return default_idx == script->n_options;
 
        if (end != var && *end == '\0')
                return default_idx == script->n_options;
 
-       /* if we don't have an explicit id for this option, fall back to
-        * the name */
-       if (!id)
-               id = opt->option->name;
+       if (id && !strcmp(id, var))
+               return true;
 
 
-       return !strcmp(id, var);
+       return !strcmp(opt->option->name, var);
 }
 
 static void append_text_to_current_arg(struct grub2_argv *argv,
 }
 
 static void append_text_to_current_arg(struct grub2_argv *argv,
index 25d1cf1e5f0b3398a7d7a6ae9fe772c6c21cc84f..d455d622770f538cc7f05cb79132238e606f8d15 100644 (file)
@@ -3,10 +3,10 @@
 
 #if 0 /* PARSER_EMBEDDED_CONFIG */
 set default="Multiple word option"
 
 #if 0 /* PARSER_EMBEDDED_CONFIG */
 set default="Multiple word option"
-menuentry 'Non-defalt option' {
+menuentry 'Non-defalt option' --id=option0 {
        linux /vmlinux.non-default
 }
        linux /vmlinux.non-default
 }
-menuentry 'Multiple word option' {
+menuentry 'Multiple word option' --id=option1 {
        linux   /vmlinux
 }
 #endif
        linux   /vmlinux
 }
 #endif