nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0031-Try-prefix-if-fw_path-doesn-t-work.patch

8e15ce
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8e15ce
From: Peter Jones <pjones@redhat.com>
8e15ce
Date: Tue, 9 Jul 2019 10:35:16 +0200
8e15ce
Subject: [PATCH] Try $prefix if $fw_path doesn't work.
8e15ce
8e15ce
Related: rhbz#1148652
8e15ce
8e15ce
Signed-off-by: Peter Jones <pjones@redhat.com>
8e15ce
---
8e15ce
 grub-core/kern/ieee1275/init.c |  28 +++++----
8e15ce
 grub-core/net/net.c            |   2 +-
8e15ce
 grub-core/normal/main.c        | 134 ++++++++++++++++++++---------------------
8e15ce
 3 files changed, 82 insertions(+), 82 deletions(-)
8e15ce
8e15ce
diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
b35c50
index e71d158416..0cd2a62723 100644
8e15ce
--- a/grub-core/kern/ieee1275/init.c
8e15ce
+++ b/grub-core/kern/ieee1275/init.c
8e15ce
@@ -127,23 +127,25 @@ grub_machine_get_bootlocation (char **device, char **path)
8e15ce
       grub_free (canon);
8e15ce
     }
8e15ce
   else
8e15ce
-    *device = grub_ieee1275_encode_devname (bootpath);
8e15ce
-  grub_free (type);
8e15ce
-
8e15ce
-  filename = grub_ieee1275_get_filename (bootpath);
8e15ce
-  if (filename)
8e15ce
     {
8e15ce
-      char *lastslash = grub_strrchr (filename, '\\');
8e15ce
-
8e15ce
-      /* Truncate at last directory.  */
8e15ce
-      if (lastslash)
8e15ce
+      filename = grub_ieee1275_get_filename (bootpath);
8e15ce
+      if (filename)
8e15ce
         {
8e15ce
-	  *lastslash = '\0';
8e15ce
-	  grub_translate_ieee1275_path (filename);
8e15ce
+          char *lastslash = grub_strrchr (filename, '\\');
8e15ce
 
8e15ce
-	  *path = filename;
8e15ce
-	}
8e15ce
+          /* Truncate at last directory.  */
8e15ce
+          if (lastslash)
8e15ce
+            {
8e15ce
+              *lastslash = '\0';
8e15ce
+              grub_translate_ieee1275_path (filename);
8e15ce
+
8e15ce
+              *path = filename;
8e15ce
+            }
8e15ce
+        }
8e15ce
+      *device = grub_ieee1275_encode_devname (bootpath);
8e15ce
     }
8e15ce
+
8e15ce
+  grub_free (type);
8e15ce
   grub_free (bootpath);
8e15ce
 }
8e15ce
 
8e15ce
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
b35c50
index 4d3eb5c1a5..0ef148f4ad 100644
8e15ce
--- a/grub-core/net/net.c
8e15ce
+++ b/grub-core/net/net.c
8e15ce
@@ -1869,7 +1869,7 @@ grub_net_search_config_file (char *config)
8e15ce
   /* Remove the remaining minus sign at the end. */
8e15ce
   config[config_len] = '\0';
8e15ce
 
8e15ce
-  return GRUB_ERR_NONE;
8e15ce
+  return GRUB_ERR_FILE_NOT_FOUND;
8e15ce
 }
8e15ce
 
8e15ce
 static struct grub_preboot *fini_hnd;
8e15ce
diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c
b35c50
index 0a99768f75..55558cc0b9 100644
8e15ce
--- a/grub-core/normal/main.c
8e15ce
+++ b/grub-core/normal/main.c
b35c50
@@ -335,81 +335,79 @@ grub_enter_normal_mode (const char *config)
8e15ce
   grub_boot_time ("Exiting normal mode");
8e15ce
 }
8e15ce
 
8e15ce
+static grub_err_t
8e15ce
+grub_try_normal (const char *variable)
8e15ce
+{
8e15ce
+    char *config;
8e15ce
+    const char *prefix;
8e15ce
+    grub_err_t err = GRUB_ERR_FILE_NOT_FOUND;
8e15ce
+    const char *net_search_cfg;
8e15ce
+    int disable_net_search = 0;
8e15ce
+
8e15ce
+    prefix = grub_env_get (variable);
8e15ce
+    if (!prefix)
8e15ce
+      return GRUB_ERR_FILE_NOT_FOUND;
8e15ce
+
8e15ce
+    net_search_cfg = grub_env_get ("feature_net_search_cfg");
8e15ce
+    if (net_search_cfg && net_search_cfg[0] == 'n')
8e15ce
+      disable_net_search = 1;
8e15ce
+
8e15ce
+    if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 &&
8e15ce
+        !disable_net_search)
8e15ce
+      {
8e15ce
+       grub_size_t config_len;
8e15ce
+       config_len = grub_strlen (prefix) +
8e15ce
+         sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
8e15ce
+       config = grub_malloc (config_len);
8e15ce
+
8e15ce
+       if (! config)
8e15ce
+         return GRUB_ERR_FILE_NOT_FOUND;
8e15ce
+
8e15ce
+       grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
8e15ce
+       err = grub_net_search_config_file (config);
8e15ce
+      }
8e15ce
+
8e15ce
+    if (err != GRUB_ERR_NONE)
8e15ce
+      {
8e15ce
+       config = grub_xasprintf ("%s/grub.cfg", prefix);
8e15ce
+       if (config)
8e15ce
+         {
8e15ce
+           grub_file_t file;
8e15ce
+           file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
8e15ce
+           if (file)
8e15ce
+             {
8e15ce
+               grub_file_close (file);
8e15ce
+               err = GRUB_ERR_NONE;
8e15ce
+             }
8e15ce
+         }
8e15ce
+      }
8e15ce
+
8e15ce
+    if (err == GRUB_ERR_NONE)
8e15ce
+      grub_enter_normal_mode (config);
8e15ce
+
8e15ce
+    grub_errno = 0;
8e15ce
+    grub_free (config);
8e15ce
+    return err;
8e15ce
+}
8e15ce
+
8e15ce
 /* Enter normal mode from rescue mode.  */
8e15ce
 static grub_err_t
8e15ce
 grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
8e15ce
 		 int argc, char *argv[])
8e15ce
 {
8e15ce
-  if (argc == 0)
8e15ce
-    {
8e15ce
-      /* Guess the config filename. It is necessary to make CONFIG static,
8e15ce
-	 so that it won't get broken by longjmp.  */
8e15ce
-      char *config;
8e15ce
-      const char *prefix;
8e15ce
-      const char *net_search_cfg;
8e15ce
-      int disable_net_search = 0;
8e15ce
-
8e15ce
-      prefix = grub_env_get ("fw_path");
8e15ce
-      if (! prefix)
8e15ce
-	      prefix = grub_env_get ("prefix");
8e15ce
-
8e15ce
-      net_search_cfg = grub_env_get ("feature_net_search_cfg");
8e15ce
-      if (net_search_cfg && net_search_cfg[0] == 'n')
8e15ce
-	      disable_net_search = 1;
8e15ce
-
8e15ce
-      if (prefix)
8e15ce
-        {
8e15ce
-          if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 &&
8e15ce
-              !disable_net_search)
8e15ce
-            {
8e15ce
-              grub_size_t config_len;
8e15ce
-              config_len = grub_strlen (prefix) +
8e15ce
-                sizeof ("/grub.cfg-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
8e15ce
-              config = grub_malloc (config_len);
8e15ce
-
8e15ce
-              if (! config)
8e15ce
-                goto quit;
8e15ce
-
8e15ce
-              grub_snprintf (config, config_len, "%s/grub.cfg", prefix);
8e15ce
-
8e15ce
-              grub_net_search_configfile (config);
8e15ce
-
8e15ce
-              grub_enter_normal_mode (config);
8e15ce
-              grub_free (config);
8e15ce
-              config = NULL;
8e15ce
-            }
8e15ce
-
8e15ce
-          if (!config)
8e15ce
-            {
8e15ce
-              config = grub_xasprintf ("%s/grub.cfg", prefix);
8e15ce
-              if (config)
8e15ce
-                {
8e15ce
-                  grub_file_t file;
8e15ce
-
8e15ce
-                  file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
8e15ce
-                  if (file)
8e15ce
-                    {
8e15ce
-                      grub_file_close (file);
8e15ce
-                      grub_enter_normal_mode (config);
8e15ce
-                    }
8e15ce
-                  else
8e15ce
-                    {
8e15ce
-                      /*  Ignore all errors.  */
8e15ce
-                      grub_errno = 0;
8e15ce
-                    }
8e15ce
-                  grub_free (config);
8e15ce
-                }
8e15ce
-            }
8e15ce
-        }
8e15ce
-      else
8e15ce
-        {
8e15ce
-          grub_enter_normal_mode (0);
8e15ce
-        }
8e15ce
-    }
8e15ce
-  else
8e15ce
+  if (argc)
8e15ce
     grub_enter_normal_mode (argv[0]);
8e15ce
+  else
8e15ce
+    {
8e15ce
+      /* Guess the config filename. */
8e15ce
+      grub_err_t err;
8e15ce
+      err = grub_try_normal ("fw_path");
8e15ce
+      if (err == GRUB_ERR_FILE_NOT_FOUND)
8e15ce
+        err = grub_try_normal ("prefix");
8e15ce
+      if (err == GRUB_ERR_FILE_NOT_FOUND)
8e15ce
+        grub_enter_normal_mode (0);
8e15ce
+    }
8e15ce
 
8e15ce
-quit:
8e15ce
   return 0;
8e15ce
 }
8e15ce