nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0154-Try-prefix-if-fw_path-doesn-t-work.patch

4fe85b
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
4fe85b
From: Peter Jones <pjones@redhat.com>
4fe85b
Date: Fri, 3 Oct 2014 11:08:03 -0400
4fe85b
Subject: [PATCH] Try $prefix if $fw_path doesn't work.
4fe85b
4fe85b
Related: rhbz#1148652
4fe85b
4fe85b
Signed-off-by: Peter Jones <pjones@redhat.com>
4fe85b
---
4fe85b
 grub-core/kern/ieee1275/init.c |  28 +++++-----
4fe85b
 grub-core/net/net.c            |   2 +-
4fe85b
 grub-core/normal/main.c        | 120 ++++++++++++++++++++---------------------
4fe85b
 3 files changed, 75 insertions(+), 75 deletions(-)
4fe85b
4fe85b
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
4fe85b
index 8191f8cd658..8ca4bf79f09 100644
4fe85b
--- a/grub-core/kern/ieee1275/init.c
4fe85b
+++ b/grub-core/kern/ieee1275/init.c
4fe85b
@@ -131,23 +131,25 @@ grub_machine_get_bootlocation (char **device, char **path)
4fe85b
       grub_free (canon);
4fe85b
     }
4fe85b
   else
4fe85b
-    *device = grub_ieee1275_encode_devname (bootpath);
4fe85b
-  grub_free (type);
4fe85b
-
4fe85b
-  filename = grub_ieee1275_get_filename (bootpath);
4fe85b
-  if (filename)
4fe85b
     {
4fe85b
-      char *lastslash = grub_strrchr (filename, '\\');
4fe85b
-
4fe85b
-      /* Truncate at last directory.  */
4fe85b
-      if (lastslash)
4fe85b
+      filename = grub_ieee1275_get_filename (bootpath);
4fe85b
+      if (filename)
4fe85b
         {
4fe85b
-	  *lastslash = '\0';
4fe85b
-	  grub_translate_ieee1275_path (filename);
4fe85b
+          char *lastslash = grub_strrchr (filename, '\\');
4fe85b
 
4fe85b
-	  *path = filename;
4fe85b
-	}
4fe85b
+          /* Truncate at last directory.  */
4fe85b
+          if (lastslash)
4fe85b
+            {
4fe85b
+              *lastslash = '\0';
4fe85b
+              grub_translate_ieee1275_path (filename);
4fe85b
+
4fe85b
+              *path = filename;
4fe85b
+            }
4fe85b
+        }
4fe85b
+      *device = grub_ieee1275_encode_devname (bootpath);
4fe85b
     }
4fe85b
+
4fe85b
+  grub_free (type);
4fe85b
   grub_free (bootpath);
4fe85b
 }
4fe85b
 
4fe85b
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
4fe85b
index 578e057e18f..10bfed31b2b 100644
4fe85b
--- a/grub-core/net/net.c
4fe85b
+++ b/grub-core/net/net.c
4fe85b
@@ -1817,7 +1817,7 @@ grub_net_search_configfile (char *config)
4fe85b
   /* Remove the remaining minus sign at the end. */
4fe85b
   config[config_len] = '\0';
4fe85b
 
4fe85b
-  return GRUB_ERR_NONE;
4fe85b
+  return GRUB_ERR_FILE_NOT_FOUND;
4fe85b
 }
4fe85b
 
4fe85b
 static struct grub_preboot *fini_hnd;
4fe85b
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
4fe85b
index 4190985ad37..aa14499996b 100644
4fe85b
--- a/grub-core/normal/main.c
4fe85b
+++ b/grub-core/normal/main.c
4fe85b
@@ -331,74 +331,72 @@ grub_enter_normal_mode (const char *config)
4fe85b
   grub_boot_time ("Exiting normal mode");
4fe85b
 }
4fe85b
 
4fe85b
+static grub_err_t
4fe85b
+grub_try_normal (const char *variable)
4fe85b
+{
4fe85b
+    char *config;
4fe85b
+    const char *prefix;
4fe85b
+    grub_err_t err = GRUB_ERR_FILE_NOT_FOUND;
4fe85b
+
4fe85b
+    prefix = grub_env_get (variable);
4fe85b
+    if (!prefix)
4fe85b
+      return GRUB_ERR_FILE_NOT_FOUND;
4fe85b
+
4fe85b
+    if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0)
4fe85b
+      {
4fe85b
+	grub_size_t config_len;
4fe85b
+	config_len = grub_strlen (prefix) +
4fe85b
+	  sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
4fe85b
+	config = grub_malloc (config_len);
4fe85b
+
4fe85b
+	if (! config)
4fe85b
+	  return GRUB_ERR_FILE_NOT_FOUND;
4fe85b
+
4fe85b
+	grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
4fe85b
+	err = grub_net_search_configfile (config);
4fe85b
+      }
4fe85b
+
4fe85b
+    if (err != GRUB_ERR_NONE)
4fe85b
+      {
4fe85b
+	config = grub_xasprintf ("%s/grub.cfg", prefix);
4fe85b
+	if (config)
4fe85b
+	  {
4fe85b
+	    grub_file_t file;
4fe85b
+	    file = grub_file_open (config);
4fe85b
+	    if (file)
4fe85b
+	      {
4fe85b
+		grub_file_close (file);
4fe85b
+		err = GRUB_ERR_NONE;
4fe85b
+	      }
4fe85b
+	  }
4fe85b
+      }
4fe85b
+
4fe85b
+    if (err == GRUB_ERR_NONE)
4fe85b
+      grub_enter_normal_mode (config);
4fe85b
+
4fe85b
+    grub_errno = 0;
4fe85b
+    grub_free (config);
4fe85b
+    return err;
4fe85b
+}
4fe85b
+
4fe85b
 /* Enter normal mode from rescue mode.  */
4fe85b
 static grub_err_t
4fe85b
 grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
4fe85b
 		 int argc, char *argv[])
4fe85b
 {
4fe85b
-  if (argc == 0)
4fe85b
-    {
4fe85b
-      /* Guess the config filename. It is necessary to make CONFIG static,
4fe85b
-	 so that it won't get broken by longjmp.  */
4fe85b
-      char *config;
4fe85b
-      const char *prefix;
4fe85b
-
4fe85b
-      prefix = grub_env_get ("fw_path");
4fe85b
-      if (! prefix)
4fe85b
-	      prefix = grub_env_get ("prefix");
4fe85b
-
4fe85b
-      if (prefix)
4fe85b
-	{
4fe85b
-	  if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0)
4fe85b
-	    {
4fe85b
-	      grub_size_t config_len;
4fe85b
-	      config_len = grub_strlen (prefix) +
4fe85b
-		sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
4fe85b
-	      config = grub_malloc (config_len);
4fe85b
-
4fe85b
-	      if (! config)
4fe85b
-		goto quit;
4fe85b
-
4fe85b
-	      grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
4fe85b
-
4fe85b
-	      grub_net_search_configfile (config);
4fe85b
-
4fe85b
-	      grub_enter_normal_mode (config);
4fe85b
-	      grub_free (config);
4fe85b
-	      config = NULL;
4fe85b
-	    }
4fe85b
-
4fe85b
-	  if (!config)
4fe85b
-	    {
4fe85b
-	      config = grub_xasprintf ("%s/grub.cfg", prefix);
4fe85b
-	      if (config)
4fe85b
-		{
4fe85b
-		  grub_file_t file;
4fe85b
-
4fe85b
-		  file = grub_file_open (config);
4fe85b
-		  if (file)
4fe85b
-		    {
4fe85b
-		      grub_file_close (file);
4fe85b
-		      grub_enter_normal_mode (config);
4fe85b
-		    }
4fe85b
-		  else
4fe85b
-		    {
4fe85b
-		      /*  Ignore all errors.  */
4fe85b
-		      grub_errno = 0;
4fe85b
-		    }
4fe85b
-		  grub_free (config);
4fe85b
-		}
4fe85b
-	    }
4fe85b
-	}
4fe85b
-      else
4fe85b
-	{
4fe85b
-	  grub_enter_normal_mode (0);
4fe85b
-	}
4fe85b
-    }
4fe85b
-  else
4fe85b
+  if (argc)
4fe85b
     grub_enter_normal_mode (argv[0]);
4fe85b
+  else
4fe85b
+    {
4fe85b
+      /* Guess the config filename. */
4fe85b
+      grub_err_t err;
4fe85b
+      err = grub_try_normal ("fw_path");
4fe85b
+      if (err == GRUB_ERR_FILE_NOT_FOUND)
4fe85b
+        err = grub_try_normal ("prefix");
4fe85b
+      if (err == GRUB_ERR_FILE_NOT_FOUND)
4fe85b
+        grub_enter_normal_mode (0);
4fe85b
+    }
4fe85b
 
4fe85b
-quit:
4fe85b
   return 0;
4fe85b
 }
4fe85b