nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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