2018-04-11 18:42:03 +00:00
|
|
|
From 27845fb323de35e9dcaad8c738eb1a2a2bc316f8 Mon Sep 17 00:00:00 2001
|
2014-09-29 15:48:01 +00:00
|
|
|
From: Peter Jones <pjones@redhat.com>
|
|
|
|
Date: Fri, 5 Sep 2014 10:07:04 -0400
|
2018-07-11 18:57:33 +00:00
|
|
|
Subject: [PATCH] Allow "fallback" to include entries by title, not just
|
|
|
|
number.
|
2014-09-29 15:48:01 +00:00
|
|
|
|
|
|
|
Resolves: rhbz#1026084
|
|
|
|
|
|
|
|
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
|
---
|
2016-04-05 19:28:47 +00:00
|
|
|
grub-core/normal/menu.c | 85 +++++++++++++++++++++++++++++++++----------------
|
|
|
|
1 file changed, 58 insertions(+), 27 deletions(-)
|
2014-09-29 15:48:01 +00:00
|
|
|
|
|
|
|
diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
|
2018-02-27 18:56:41 +00:00
|
|
|
index e7a83c2d6e2..d2f64b05e0a 100644
|
2014-09-29 15:48:01 +00:00
|
|
|
--- a/grub-core/normal/menu.c
|
|
|
|
+++ b/grub-core/normal/menu.c
|
2016-04-05 19:28:47 +00:00
|
|
|
@@ -163,16 +163,41 @@ grub_menu_set_timeout (int timeout)
|
2014-09-29 15:48:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+static int
|
|
|
|
+menuentry_eq (const char *id, const char *spec)
|
|
|
|
+{
|
|
|
|
+ const char *ptr1, *ptr2;
|
|
|
|
+ ptr1 = id;
|
|
|
|
+ ptr2 = spec;
|
|
|
|
+ while (1)
|
|
|
|
+ {
|
|
|
|
+ if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
|
2016-04-05 19:28:47 +00:00
|
|
|
+ return ptr2 - spec;
|
2014-09-29 15:48:01 +00:00
|
|
|
+ if (*ptr2 == '>' && ptr2[1] != '>')
|
|
|
|
+ return 0;
|
|
|
|
+ if (*ptr2 == '>')
|
|
|
|
+ ptr2++;
|
|
|
|
+ if (*ptr1 != *ptr2)
|
|
|
|
+ return 0;
|
|
|
|
+ if (*ptr1 == 0)
|
2016-04-05 19:28:47 +00:00
|
|
|
+ return ptr1 - id;
|
2014-09-29 15:48:01 +00:00
|
|
|
+ ptr1++;
|
|
|
|
+ ptr2++;
|
|
|
|
+ }
|
2016-04-05 19:28:47 +00:00
|
|
|
+ return 0;
|
2014-09-29 15:48:01 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
/* Get the first entry number from the value of the environment variable NAME,
|
|
|
|
which is a space-separated list of non-negative integers. The entry number
|
|
|
|
which is returned is stripped from the value of NAME. If no entry number
|
|
|
|
can be found, -1 is returned. */
|
|
|
|
static int
|
|
|
|
-get_and_remove_first_entry_number (const char *name)
|
|
|
|
+get_and_remove_first_entry_number (grub_menu_t menu, const char *name)
|
|
|
|
{
|
|
|
|
const char *val;
|
|
|
|
char *tail;
|
2016-04-05 19:28:47 +00:00
|
|
|
int entry;
|
|
|
|
+ int sz = 0;
|
|
|
|
|
|
|
|
val = grub_env_get (name);
|
|
|
|
if (! val)
|
|
|
|
@@ -182,9 +207,39 @@ get_and_remove_first_entry_number (const char *name)
|
2014-09-29 15:48:01 +00:00
|
|
|
|
|
|
|
entry = (int) grub_strtoul (val, &tail, 0);
|
|
|
|
|
|
|
|
+ if (grub_errno == GRUB_ERR_BAD_NUMBER)
|
|
|
|
+ {
|
|
|
|
+ /* See if the variable matches the title of a menu entry. */
|
|
|
|
+ grub_menu_entry_t e = menu->entry_list;
|
|
|
|
+ int i;
|
|
|
|
+
|
|
|
|
+ for (i = 0; e; i++)
|
|
|
|
+ {
|
2016-04-05 19:28:47 +00:00
|
|
|
+ sz = menuentry_eq (e->title, val);
|
|
|
|
+ if (sz < 1)
|
|
|
|
+ sz = menuentry_eq (e->id, val);
|
|
|
|
+
|
|
|
|
+ if (sz >= 1)
|
2014-09-29 15:48:01 +00:00
|
|
|
+ {
|
|
|
|
+ entry = i;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ e = e->next;
|
|
|
|
+ }
|
|
|
|
+
|
2016-04-05 19:28:47 +00:00
|
|
|
+ if (sz > 0)
|
|
|
|
+ grub_errno = GRUB_ERR_NONE;
|
|
|
|
+
|
2014-09-29 15:48:01 +00:00
|
|
|
+ if (! e)
|
|
|
|
+ entry = -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
if (grub_errno == GRUB_ERR_NONE)
|
|
|
|
{
|
|
|
|
- /* Skip whitespace to find the next digit. */
|
2016-04-05 19:28:47 +00:00
|
|
|
+ if (sz > 0)
|
|
|
|
+ tail += sz;
|
|
|
|
+
|
2014-09-29 15:48:01 +00:00
|
|
|
+ /* Skip whitespace to find the next entry. */
|
|
|
|
while (*tail && grub_isspace (*tail))
|
|
|
|
tail++;
|
|
|
|
grub_env_set (name, tail);
|
2016-04-05 19:28:47 +00:00
|
|
|
@@ -347,7 +402,7 @@ grub_menu_execute_with_fallback (grub_menu_t menu,
|
2014-09-29 15:48:01 +00:00
|
|
|
grub_menu_execute_entry (entry, 1);
|
|
|
|
|
|
|
|
/* Deal with fallback entries. */
|
|
|
|
- while ((fallback_entry = get_and_remove_first_entry_number ("fallback"))
|
|
|
|
+ while ((fallback_entry = get_and_remove_first_entry_number (menu, "fallback"))
|
|
|
|
>= 0)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
2016-04-05 19:28:47 +00:00
|
|
|
@@ -465,30 +520,6 @@ grub_menu_register_viewer (struct grub_menu_viewer *viewer)
|
2014-09-29 15:48:01 +00:00
|
|
|
viewers = viewer;
|
|
|
|
}
|
|
|
|
|
|
|
|
-static int
|
|
|
|
-menuentry_eq (const char *id, const char *spec)
|
|
|
|
-{
|
|
|
|
- const char *ptr1, *ptr2;
|
|
|
|
- ptr1 = id;
|
|
|
|
- ptr2 = spec;
|
|
|
|
- while (1)
|
|
|
|
- {
|
|
|
|
- if (*ptr2 == '>' && ptr2[1] != '>' && *ptr1 == 0)
|
|
|
|
- return 1;
|
|
|
|
- if (*ptr2 == '>' && ptr2[1] != '>')
|
|
|
|
- return 0;
|
|
|
|
- if (*ptr2 == '>')
|
|
|
|
- ptr2++;
|
|
|
|
- if (*ptr1 != *ptr2)
|
|
|
|
- return 0;
|
|
|
|
- if (*ptr1 == 0)
|
|
|
|
- return 1;
|
|
|
|
- ptr1++;
|
|
|
|
- ptr2++;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/* Get the entry number from the variable NAME. */
|
|
|
|
static int
|
|
|
|
get_entry_number (grub_menu_t menu, const char *name)
|