]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
util/grub-install: Delay copying files to {grubdir,platdir} after install_device...
authorMate Kukri <mate.kukri@canonical.com>
Fri, 24 Nov 2023 08:32:57 +0000 (08:32 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 5 Dec 2023 14:32:30 +0000 (15:32 +0100)
Previously grub-install copied modules to grubdir before doing any
validation on the install_device.

When grub-install was called with an invalid install_device, modules
were already copied to /boot before it found out and was forced to rely
on atexit() rollback.

This patch delays copying the modules after at least some install_device
validation was done, and thus reduces reliance on successful rollback.

Signed-off-by: Mate Kukri <mate.kukri@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
util/grub-install.c

index 1ad04db3660df1cbf2a3cc55b6d4cd1e6bc441f8..9feb4ea9edab9735e94bcb3686300652b1c93425 100644 (file)
@@ -1291,13 +1291,6 @@ main (int argc, char *argv[])
        }
     }
 
-  grub_install_copy_files (grub_install_source_directory,
-                          grubdir, platform);
-
-  char *envfile = grub_util_path_concat (2, grubdir, "grubenv");
-  if (!grub_util_is_regular (envfile))
-    grub_util_create_envblk_file (envfile);
-
   size_t ndev = 0;
 
   /* Write device to a variable so we don't have to traverse /dev every time.  */
@@ -1384,18 +1377,7 @@ main (int argc, char *argv[])
                       t);
     free (t);
   }
-  load_cfg = grub_util_path_concat (2, platdir,
-                                 "load.cfg");
-
-  grub_util_unlink (load_cfg);
 
-  if (debug_image && debug_image[0])
-    {
-      load_cfg_f = grub_util_fopen (load_cfg, "wb");
-      have_load_cfg = 1;
-      fprintf (load_cfg_f, "set debug='%s'\n",
-             debug_image);
-    }
   char *prefix_drive = NULL;
   char *install_drive = NULL;
 
@@ -1419,6 +1401,26 @@ main (int argc, char *argv[])
        }
     }
 
+  grub_install_copy_files (grub_install_source_directory,
+                           grubdir, platform);
+
+  char *envfile = grub_util_path_concat (2, grubdir, "grubenv");
+  if (!grub_util_is_regular (envfile))
+    grub_util_create_envblk_file (envfile);
+
+  load_cfg = grub_util_path_concat (2, platdir,
+                                  "load.cfg");
+
+  grub_util_unlink (load_cfg);
+
+  if (debug_image && debug_image[0])
+    {
+      load_cfg_f = grub_util_fopen (load_cfg, "wb");
+      have_load_cfg = 1;
+      fprintf (load_cfg_f, "set debug='%s'\n",
+              debug_image);
+    }
+
   if (!have_abstractions)
     {
       if ((disk_module && grub_strcmp (disk_module, "biosdisk") != 0)