nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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