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

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