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

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