Blame SOURCES/0132-Try-mac-guid-etc-before-grub.cfg-on-tftp-config-file.patch

d41074
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
a85e8e
From: Peter Jones <pjones@redhat.com>
a85e8e
Date: Thu, 6 Mar 2014 11:51:33 -0500
d41074
Subject: [PATCH] Try mac/guid/etc before grub.cfg on tftp config files.
a85e8e
a85e8e
Signed-off-by: Peter Jones <pjones@redhat.com>
a85e8e
---
a85e8e
 grub-core/normal/main.c | 80 ++++++++++++++++++++++++++-----------------------
a85e8e
 1 file changed, 43 insertions(+), 37 deletions(-)
a85e8e
a85e8e
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
d41074
index 5e2ac150e12..4190985ad37 100644
a85e8e
--- a/grub-core/normal/main.c
a85e8e
+++ b/grub-core/normal/main.c
a85e8e
@@ -341,53 +341,59 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
a85e8e
       /* Guess the config filename. It is necessary to make CONFIG static,
a85e8e
 	 so that it won't get broken by longjmp.  */
a85e8e
       char *config;
a85e8e
-      const char *prefix, *fw_path;
a85e8e
-
a85e8e
-      prefix = fw_path = grub_env_get ("fw_path");
a85e8e
-      if (fw_path)
a85e8e
-	{
a85e8e
-	  config = grub_xasprintf ("%s/grub.cfg", fw_path);
a85e8e
-	  if (config)
a85e8e
-	    {
a85e8e
-	      grub_file_t file;
a85e8e
-
a85e8e
-	      file = grub_file_open (config);
a85e8e
-	      if (file)
a85e8e
-		{
a85e8e
-		  grub_file_close (file);
a85e8e
-		  grub_enter_normal_mode (config);
a85e8e
-		}
a85e8e
-              else
a85e8e
-                {
a85e8e
-                  /*  Ignore all errors.  */
a85e8e
-                  grub_errno = 0;
a85e8e
-                }
a85e8e
-	      grub_free (config);
a85e8e
-	    }
a85e8e
-	}
a85e8e
+      const char *prefix;
a85e8e
 
a85e8e
+      prefix = grub_env_get ("fw_path");
a85e8e
       if (! prefix)
a85e8e
 	      prefix = grub_env_get ("prefix");
a85e8e
+
a85e8e
       if (prefix)
a85e8e
-        {
a85e8e
-          grub_size_t config_len;
a85e8e
-          config_len = grub_strlen (prefix) +
a85e8e
-                      sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
a85e8e
-          config = grub_malloc (config_len);
a85e8e
+	{
a85e8e
+	  if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0)
a85e8e
+	    {
a85e8e
+	      grub_size_t config_len;
a85e8e
+	      config_len = grub_strlen (prefix) +
a85e8e
+		sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
a85e8e
+	      config = grub_malloc (config_len);
a85e8e
 
a85e8e
-          if (! config)
a85e8e
-            goto quit;
d41074
+	      if (! config)
d41074
+		goto quit;
a85e8e
 
a85e8e
-          grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
d41074
+	      grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
a85e8e
 
a85e8e
-          if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0)
a85e8e
-            grub_net_search_configfile (config);
d41074
+	      grub_net_search_configfile (config);
d41074
 
d41074
-	  grub_enter_normal_mode (config);
d41074
-	  grub_free (config);
a85e8e
+	      grub_enter_normal_mode (config);
a85e8e
+	      grub_free (config);
a85e8e
+	      config = NULL;
a85e8e
+	    }
d41074
+
a85e8e
+	  if (!config)
a85e8e
+	    {
a85e8e
+	      config = grub_xasprintf ("%s/grub.cfg", prefix);
a85e8e
+	      if (config)
a85e8e
+		{
a85e8e
+		  grub_file_t file;
a85e8e
+
a85e8e
+		  file = grub_file_open (config);
a85e8e
+		  if (file)
a85e8e
+		    {
a85e8e
+		      grub_file_close (file);
a85e8e
+		      grub_enter_normal_mode (config);
a85e8e
+		    }
a85e8e
+		  else
a85e8e
+		    {
a85e8e
+		      /*  Ignore all errors.  */
a85e8e
+		      grub_errno = 0;
a85e8e
+		    }
a85e8e
+		  grub_free (config);
a85e8e
+		}
a85e8e
+	    }
a85e8e
 	}
a85e8e
       else
a85e8e
-	grub_enter_normal_mode (0);
a85e8e
+	{
a85e8e
+	  grub_enter_normal_mode (0);
a85e8e
+	}
a85e8e
     }
a85e8e
   else
a85e8e
     grub_enter_normal_mode (argv[0]);