nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0150-Allow-fallback-to-include-entries-by-title-not-just-.patch

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