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

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