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