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

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