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

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