|
|
5593c8 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
5593c8 |
From: Peter Jones <pjones@redhat.com>
|
|
|
5593c8 |
Date: Fri, 5 Sep 2014 10:07:04 -0400
|
|
|
5593c8 |
Subject: [PATCH] Allow "fallback" to include entries by title, not just
|
|
|
5593c8 |
number.
|
|
|
5593c8 |
|
|
|
5593c8 |
Resolves: rhbz#1026084
|
|
|
5593c8 |
|
|
|
5593c8 |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
5593c8 |
---
|
|
|
5593c8 |
grub-core/normal/menu.c | 85 +++++++++++++++++++++++++++++++++----------------
|
|
|
5593c8 |
1 file changed, 58 insertions(+), 27 deletions(-)
|
|
|
5593c8 |
|
|
|
5593c8 |
diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
|
|
|
d3c3ab |
index 8397886fa05..d7a222e681b 100644
|
|
|
5593c8 |
--- a/grub-core/normal/menu.c
|
|
|
5593c8 |
+++ b/grub-core/normal/menu.c
|
|
|
5593c8 |
@@ -163,15 +163,40 @@ grub_menu_set_timeout (int timeout)
|
|
|
5593c8 |
}
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
+static int
|
|
|
5593c8 |
+menuentry_eq (const char *id, const char *spec)
|
|
|
5593c8 |
+{
|
|
|
5593c8 |
+ const char *ptr1, *ptr2;
|
|
|
5593c8 |
+ ptr1 = id;
|
|
|
5593c8 |
+ ptr2 = spec;
|
|
|
5593c8 |
+ while (1)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
|
|
|
5593c8 |
+ return ptr2 - spec;
|
|
|
5593c8 |
+ if (*ptr2 == '>' && ptr2[1] != '>')
|
|
|
5593c8 |
+ return 0;
|
|
|
5593c8 |
+ if (*ptr2 == '>')
|
|
|
5593c8 |
+ ptr2++;
|
|
|
5593c8 |
+ if (*ptr1 != *ptr2)
|
|
|
5593c8 |
+ return 0;
|
|
|
5593c8 |
+ if (*ptr1 == 0)
|
|
|
5593c8 |
+ return ptr1 - id;
|
|
|
5593c8 |
+ ptr1++;
|
|
|
5593c8 |
+ ptr2++;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+ return 0;
|
|
|
5593c8 |
+}
|
|
|
5593c8 |
+
|
|
|
5593c8 |
/* Get the first entry number from the value of the environment variable NAME,
|
|
|
5593c8 |
which is a space-separated list of non-negative integers. The entry number
|
|
|
5593c8 |
which is returned is stripped from the value of NAME. If no entry number
|
|
|
5593c8 |
can be found, -1 is returned. */
|
|
|
5593c8 |
static int
|
|
|
5593c8 |
-get_and_remove_first_entry_number (const char *name)
|
|
|
5593c8 |
+get_and_remove_first_entry_number (grub_menu_t menu, const char *name)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
const char *val, *tail;
|
|
|
5593c8 |
int entry;
|
|
|
5593c8 |
+ int sz = 0;
|
|
|
5593c8 |
|
|
|
5593c8 |
val = grub_env_get (name);
|
|
|
5593c8 |
if (! val)
|
|
|
5593c8 |
@@ -181,9 +206,39 @@ get_and_remove_first_entry_number (const char *name)
|
|
|
5593c8 |
|
|
|
5593c8 |
entry = (int) grub_strtoul (val, &tail, 0);
|
|
|
5593c8 |
|
|
|
5593c8 |
+ if (grub_errno == GRUB_ERR_BAD_NUMBER)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ /* See if the variable matches the title of a menu entry. */
|
|
|
5593c8 |
+ grub_menu_entry_t e = menu->entry_list;
|
|
|
5593c8 |
+ int i;
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ for (i = 0; e; i++)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ sz = menuentry_eq (e->title, val);
|
|
|
5593c8 |
+ if (sz < 1)
|
|
|
5593c8 |
+ sz = menuentry_eq (e->id, val);
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ if (sz >= 1)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ entry = i;
|
|
|
5593c8 |
+ break;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+ e = e->next;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ if (sz > 0)
|
|
|
5593c8 |
+ grub_errno = GRUB_ERR_NONE;
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ if (! e)
|
|
|
5593c8 |
+ entry = -1;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+
|
|
|
5593c8 |
if (grub_errno == GRUB_ERR_NONE)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- /* Skip whitespace to find the next digit. */
|
|
|
5593c8 |
+ if (sz > 0)
|
|
|
5593c8 |
+ tail += sz;
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ /* Skip whitespace to find the next entry. */
|
|
|
5593c8 |
while (*tail && grub_isspace (*tail))
|
|
|
5593c8 |
tail++;
|
|
|
5593c8 |
grub_env_set (name, tail);
|
|
|
5593c8 |
@@ -346,7 +401,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu,
|
|
|
5593c8 |
grub_menu_execute_entry (entry, 1);
|
|
|
5593c8 |
|
|
|
5593c8 |
/* Deal with fallback entries. */
|
|
|
5593c8 |
- while ((fallback_entry = get_and_remove_first_entry_number ("fallback"))
|
|
|
5593c8 |
+ while ((fallback_entry = get_and_remove_first_entry_number (menu, "fallback"))
|
|
|
5593c8 |
>= 0)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
grub_print_error ();
|
|
|
5593c8 |
@@ -464,30 +519,6 @@ grub_menu_register_viewer (struct grub_menu_viewer *viewer)
|
|
|
5593c8 |
viewers = viewer;
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
-static int
|
|
|
5593c8 |
-menuentry_eq (const char *id, const char *spec)
|
|
|
5593c8 |
-{
|
|
|
5593c8 |
- const char *ptr1, *ptr2;
|
|
|
5593c8 |
- ptr1 = id;
|
|
|
5593c8 |
- ptr2 = spec;
|
|
|
5593c8 |
- while (1)
|
|
|
5593c8 |
- {
|
|
|
5593c8 |
- if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
|
|
|
5593c8 |
- return 1;
|
|
|
5593c8 |
- if (*ptr2 == '>' && ptr2[1] != '>')
|
|
|
5593c8 |
- return 0;
|
|
|
5593c8 |
- if (*ptr2 == '>')
|
|
|
5593c8 |
- ptr2++;
|
|
|
5593c8 |
- if (*ptr1 != *ptr2)
|
|
|
5593c8 |
- return 0;
|
|
|
5593c8 |
- if (*ptr1 == 0)
|
|
|
5593c8 |
- return 1;
|
|
|
5593c8 |
- ptr1++;
|
|
|
5593c8 |
- ptr2++;
|
|
|
5593c8 |
- }
|
|
|
5593c8 |
-}
|
|
|
5593c8 |
-
|
|
|
5593c8 |
-
|
|
|
5593c8 |
/* Get the entry number from the variable NAME. */
|
|
|
5593c8 |
static int
|
|
|
5593c8 |
get_entry_number (grub_menu_t menu, const char *name)
|