nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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