nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0140-blscfg-handle-multiple-initramfs-images.patch

8631a2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8631a2
From: Peter Jones <pjones@redhat.com>
8631a2
Date: Wed, 11 Apr 2018 13:44:29 -0400
8631a2
Subject: [PATCH] blscfg: handle multiple initramfs images.
8631a2
8631a2
Signed-off-by: Peter Jones <pjones@redhat.com>
8631a2
---
8631a2
 grub-core/commands/blscfg.c | 54 ++++++++++++++++++++++++++++++++++++---------
8631a2
 1 file changed, 44 insertions(+), 10 deletions(-)
8631a2
8631a2
diff --git a/grub-core/commands/blscfg.c b/grub-core/commands/blscfg.c
8631a2
index e775c6b8794..6ab85df6b3a 100644
8631a2
--- a/grub-core/commands/blscfg.c
8631a2
+++ b/grub-core/commands/blscfg.c
8631a2
@@ -587,6 +587,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile)
8631a2
   char *title = NULL;
8631a2
   char *clinux = NULL;
8631a2
   char *options = NULL;
8631a2
+  char **initrds = NULL;
8631a2
   char *initrd = NULL;
8631a2
   char *id = NULL;
8631a2
   char *hotkey = NULL;
8631a2
@@ -609,7 +610,7 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile)
8631a2
 
8631a2
   title = bls_get_val (entry, "title", NULL);
8631a2
   options = bls_get_val (entry, "options", NULL);
8631a2
-  initrd = bls_get_val (entry, "initrd", NULL);
8631a2
+  initrds = bls_make_list (entry, "initrd", NULL);
8631a2
   id = bls_get_val (entry, "id", NULL);
8631a2
 
8631a2
   hotkey = bls_get_val (entry, "grub_hotkey", NULL);
8631a2
@@ -624,30 +625,63 @@ static void create_entry (struct bls_entry *entry, const char *cfgfile)
8631a2
     argv[i] = args[i-1];
8631a2
   argv[argc] = NULL;
8631a2
 
8631a2
-  grub_dprintf("blscfg", "adding menu entry for \"%s\"\n", title);
8631a2
+  grub_dprintf ("blscfg", "adding menu entry for \"%s\"\n", title);
8631a2
+  if (initrds)
8631a2
+    {
8631a2
+      int initrd_size = sizeof (GRUB_INITRD_CMD);
8631a2
+      char *tmp;
8631a2
+
8631a2
+      for (i = 0; initrds != NULL && initrds[i] != NULL; i++)
8631a2
+	initrd_size += sizeof (" " GRUB_BOOT_DEVICE) \
8631a2
+		       + grub_strlen (initrds[i]) + 1;
8631a2
+      initrd_size += 1;
8631a2
+
8631a2
+      initrd = grub_malloc (initrd_size);
8631a2
+      if (!initrd)
8631a2
+	{
8631a2
+	  grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
8631a2
+	  goto finish;
8631a2
+	}
8631a2
+
8631a2
+
8631a2
+      tmp = grub_stpcpy(initrd, GRUB_INITRD_CMD);
8631a2
+      for (i = 0; initrds != NULL && initrds[i] != NULL; i++)
8631a2
+	{
8631a2
+	  grub_dprintf ("blscfg", "adding initrd %s\n", initrds[i]);
8631a2
+	  tmp = grub_stpcpy (tmp, " " GRUB_BOOT_DEVICE);
8631a2
+	  tmp = grub_stpcpy (tmp, initrds[i]);
8631a2
+	}
8631a2
+      tmp = grub_stpcpy (tmp, "\n");
8631a2
+    }
8631a2
+
8631a2
   src = grub_xasprintf ("load_video\n"
8631a2
 			"set gfx_payload=keep\n"
8631a2
 			"insmod gzio\n"
8631a2
 			GRUB_LINUX_CMD " %s%s%s%s\n"
8631a2
-			"%s%s%s%s",
8631a2
+			"%s",
8631a2
 			GRUB_BOOT_DEVICE, clinux, options ? " " : "", options ? options : "",
8631a2
-			initrd ? GRUB_INITRD_CMD " " : "", initrd ? GRUB_BOOT_DEVICE : "", initrd ? initrd : "", initrd ? "\n" : "");
8631a2
+			initrd ? initrd : "");
8631a2
 
8631a2
   grub_normal_add_menu_entry (argc, argv, classes, id, users, hotkey, NULL, src, 0);
8631a2
 
8631a2
 finish:
8631a2
+  if (initrd)
8631a2
+    grub_free (initrd);
8631a2
+
8631a2
+  if (initrds)
8631a2
+    grub_free (initrds);
8631a2
+
8631a2
   if (classes)
8631a2
-      grub_free (classes);
8631a2
-  grub_dprintf("blscfg", "%s got here\n", __func__);
8631a2
+    grub_free (classes);
8631a2
+
8631a2
   if (args)
8631a2
-      grub_free (args);
8631a2
+    grub_free (args);
8631a2
 
8631a2
   if (argv)
8631a2
-      grub_free (argv);
8631a2
+    grub_free (argv);
8631a2
 
8631a2
   if (src)
8631a2
-      grub_free (src);
8631a2
-  grub_dprintf("blscfg", "%s got here\n", __func__);
8631a2
+    grub_free (src);
8631a2
 }
8631a2
 
8631a2
 struct find_entry_info {