Blame SOURCES/0090-Add-fw_path-variable-revised.patch

f731ee
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f731ee
From: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
f731ee
Date: Wed, 19 Sep 2012 21:22:55 -0300
f731ee
Subject: [PATCH] Add fw_path variable (revised)
f731ee
f731ee
This patch makes grub look for its config file on efi where the app was
f731ee
found. It was originally written by Matthew Garrett, and adapted to fix the
f731ee
"No modules are loaded on grub2 network boot" issue:
f731ee
f731ee
https://bugzilla.redhat.com/show_bug.cgi?id=857936
f731ee
---
f731ee
 grub-core/kern/main.c   | 13 ++++++-------
f731ee
 grub-core/normal/main.c | 25 ++++++++++++++++++++++++-
f731ee
 2 files changed, 30 insertions(+), 8 deletions(-)
f731ee
f731ee
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
f731ee
index 9cad0c4485c..8ab7794c47b 100644
f731ee
--- a/grub-core/kern/main.c
f731ee
+++ b/grub-core/kern/main.c
f731ee
@@ -127,16 +127,15 @@ grub_set_prefix_and_root (void)
f731ee
 
f731ee
   grub_machine_get_bootlocation (&fwdevice, &fwpath);
f731ee
 
f731ee
-  if (fwdevice)
f731ee
+  if (fwdevice && fwpath)
f731ee
     {
f731ee
-      char *cmdpath;
f731ee
+      char *fw_path;
f731ee
 
f731ee
-      cmdpath = grub_xasprintf ("(%s)%s", fwdevice, fwpath ? : "");
f731ee
-      if (cmdpath)
f731ee
+      fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
f731ee
+      if (fw_path)
f731ee
 	{
f731ee
-	  grub_env_set ("cmdpath", cmdpath);
f731ee
-	  grub_env_export ("cmdpath");
f731ee
-	  grub_free (cmdpath);
f731ee
+	  grub_env_set ("fw_path", fw_path);
f731ee
+	  grub_free (fw_path);
f731ee
 	}
f731ee
     }
f731ee
 
f731ee
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
f731ee
index 3a926fc5fa9..6f4970f71c1 100644
f731ee
--- a/grub-core/normal/main.c
f731ee
+++ b/grub-core/normal/main.c
f731ee
@@ -319,7 +319,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
f731ee
       /* Guess the config filename. It is necessary to make CONFIG static,
f731ee
 	 so that it won't get broken by longjmp.  */
f731ee
       char *config;
f731ee
-      const char *prefix;
f731ee
+      const char *prefix, *fw_path;
f731ee
+
f731ee
+      fw_path = grub_env_get ("fw_path");
f731ee
+      if (fw_path)
f731ee
+	{
f731ee
+	  config = grub_xasprintf ("%s/grub.cfg", fw_path);
f731ee
+	  if (config)
f731ee
+	    {
f731ee
+	      grub_file_t file;
f731ee
+
f731ee
+	      file = grub_file_open (config);
f731ee
+	      if (file)
f731ee
+		{
f731ee
+		  grub_file_close (file);
f731ee
+		  grub_enter_normal_mode (config);
f731ee
+		}
f731ee
+              else
f731ee
+                {
f731ee
+                  /*  Ignore all errors.  */
f731ee
+                  grub_errno = 0;
f731ee
+                }
f731ee
+	      grub_free (config);
f731ee
+	    }
f731ee
+	}
f731ee
 
f731ee
       prefix = grub_env_get ("prefix");
f731ee
       if (prefix)