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

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