Add fw_path variable to detect config file on efi
authorPaulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Mon, 9 Jan 2023 23:30:38 +0000 (18:30 -0500)
committerFelix Zielcke <fzielcke@z-51.de>
Mon, 15 Jul 2024 15:05:20 +0000 (17:05 +0200)
This patch makes grub look for its config file on efi where the app was
found.

Resolves: rhbz#857936, rhbz#1616395
Co-authored-by: Matthew Garrett
Co-authored-by: Javier Martinez Canillas <javierm@redhat.com>
Co-authored-by: Robbie Harwood <rharwood@redhat.com>
Signed-off-by: Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Gbp-Pq: Topic network
Gbp-Pq: Name add-fw_path-variable-to-detect-config-file-on-efi.patch

grub-core/kern/main.c
grub-core/normal/main.c

index f21376e7cde2fa0c4688d2087344c5ebe22f1994..067823793e87d00be0f3c96033bba447f5838a11 100644 (file)
@@ -128,16 +128,16 @@ grub_set_prefix_and_root (void)
 
   grub_machine_get_bootlocation (&fwdevice, &fwpath);
 
-  if (fwdevice)
+  if (fwdevice && fwpath)
     {
-      char *cmdpath;
+      char *fw_path;
 
-      cmdpath = grub_xasprintf ("(%s)%s", fwdevice, fwpath ? : "");
-      if (cmdpath)
+      fw_path = grub_xasprintf ("(%s)/%s", fwdevice, fwpath);
+      if (fw_path)
        {
-         grub_env_set ("cmdpath", cmdpath);
-         grub_env_export ("cmdpath");
-         grub_free (cmdpath);
+         grub_env_set ("fw_path", fw_path);
+         grub_env_export ("fw_path");
+         grub_free (fw_path);
        }
     }
 
index 4f10c0001c396de10049bda50472545dcbea4cf8..b1947c7af8a16cf2c689c7636d4b8670117d4bde 100644 (file)
@@ -320,7 +320,30 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)),
       /* Guess the config filename. It is necessary to make CONFIG static,
         so that it won't get broken by longjmp.  */
       char *config;
-      const char *prefix;
+      const char *prefix, *fw_path;
+
+      fw_path = grub_env_get ("fw_path");
+      if (fw_path)
+       {
+         config = grub_xasprintf ("%s/grub.cfg", fw_path);
+         if (config)
+           {
+             grub_file_t file;
+
+             file = grub_file_open (config, GRUB_FILE_TYPE_CONFIG);
+             if (file)
+               {
+                 grub_file_close (file);
+                 grub_enter_normal_mode (config);
+               }
+              else
+                {
+                  /* Ignore all errors.  */
+                  grub_errno = 0;
+                }
+             grub_free (config);
+           }
+       }
 
       prefix = grub_env_get ("prefix");
       if (prefix)