nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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