Blame SOURCES/0017-Strip-the-LT_END-line-from-a-new-stanza-before-addin.patch

56d25d
From c898c55191a129aade1ed8c3419996074b6f5ab9 Mon Sep 17 00:00:00 2001
56d25d
From: Peter Jones <pjones@redhat.com>
56d25d
Date: Wed, 21 May 2014 16:40:23 -0400
56d25d
Subject: [PATCH 17/41] Strip the LT_END line from a new stanza before adding
56d25d
 "missing" parts.
56d25d
56d25d
When we get --copy-default on a --add-kernel with a --initrd option, and
56d25d
the default stanza lacks an initrd, we wind up in the fallback path
56d25d
where we add the default after the fact.  When we do this, we later add
56d25d
an LT_END line /if/ it doesn't exist.  But we've already got one, and
56d25d
when we add the initrd it's after it.
56d25d
56d25d
So strip it out and re-mark it as needed so it'll be added at the end.
56d25d
56d25d
Resolves: rhbz#1099627
56d25d
Related: rhbz#1096358
56d25d
56d25d
Signed-off-by: Peter Jones <pjones@redhat.com>
56d25d
---
56d25d
 grubby.c                 |   7 +++
56d25d
 test.sh                  |   5 ++
56d25d
 test/grub2.14            | 111 +++++++++++++++++++++++++++++++++++++++++
56d25d
 test/results/add/g2-1.14 | 126 +++++++++++++++++++++++++++++++++++++++++++++++
56d25d
 4 files changed, 249 insertions(+)
56d25d
 create mode 100644 test/grub2.14
56d25d
 create mode 100644 test/results/add/g2-1.14
56d25d
56d25d
diff --git a/grubby.c b/grubby.c
56d25d
index 3485d4e..4516b92 100644
56d25d
--- a/grubby.c
56d25d
+++ b/grubby.c
56d25d
@@ -4014,6 +4014,13 @@ int addNewKernel(struct grubConfig * config, struct singleEntry * template,
56d25d
 	}
56d25d
     } 
56d25d
 
56d25d
+    struct singleLine *endLine = NULL;
56d25d
+    endLine = getLineByType(LT_ENTRY_END, new->lines);
56d25d
+    if (endLine) {
56d25d
+	    removeLine(new, endLine);
56d25d
+	    needs |= NEED_END;
56d25d
+    }
56d25d
+
56d25d
     /* add the remainder of the lines, i.e. those that either
56d25d
      * weren't present in the template, or in the case of no template,
56d25d
      * all the lines following the entryStart.
56d25d
diff --git a/test.sh b/test.sh
56d25d
index 50a2d25..57e4926 100755
56d25d
--- a/test.sh
56d25d
+++ b/test.sh
56d25d
@@ -511,6 +511,11 @@ if [ "$testgrub2" == "y" ]; then
56d25d
     grub2Test grub2.5 add/g2-1.5 --add-kernel=/boot/new-kernel.img \
56d25d
         --title='title' --initrd=/boot/new-initrd --boot-filesystem=/boot/ \
56d25d
         --copy-default
56d25d
+    grub2Test grub2.14 add/g2-1.14 \
56d25d
+        --add-kernel=/boot/vmlinuz-0-rescue-5a94251776a14678911d4ae0949500f5 \
56d25d
+        --initrd /boot/initramfs-0-rescue-5a94251776a14678911d4ae0949500f5.img \
56d25d
+        --copy-default --title "Fedora 21 Rescue" --args=root=/fooooo \
56d25d
+        --remove-kernel=wtf
56d25d
 
56d25d
     testing="GRUB2 add initrd"
56d25d
     grub2Test grub2.2 add/g2-1.4 --update-kernel=/boot/new-kernel.img \
56d25d
diff --git a/test/grub2.14 b/test/grub2.14
56d25d
new file mode 100644
56d25d
index 0000000..cb0304e
56d25d
--- /dev/null
56d25d
+++ b/test/grub2.14
56d25d
@@ -0,0 +1,111 @@
56d25d
+#
56d25d
+# DO NOT EDIT THIS FILE
56d25d
+#
56d25d
+# It is automatically generated by grub2-mkconfig using templates
56d25d
+# from /etc/grub.d and settings from /etc/default/grub
56d25d
+#
56d25d
+
56d25d
+### BEGIN /etc/grub.d/00_header ###
56d25d
+set pager=1
56d25d
+
56d25d
+if [ -s $prefix/grubenv ]; then
56d25d
+  load_env
56d25d
+fi
56d25d
+if [ "${next_entry}" ] ; then
56d25d
+   set default="${next_entry}"
56d25d
+   set next_entry=
56d25d
+   save_env next_entry
56d25d
+   set boot_once=true
56d25d
+else
56d25d
+   set default="${saved_entry}"
56d25d
+fi
56d25d
+
56d25d
+if [ x"${feature_menuentry_id}" = xy ]; then
56d25d
+  menuentry_id_option="--id"
56d25d
+else
56d25d
+  menuentry_id_option=""
56d25d
+fi
56d25d
+
56d25d
+export menuentry_id_option
56d25d
+
56d25d
+if [ "${prev_saved_entry}" ]; then
56d25d
+  set saved_entry="${prev_saved_entry}"
56d25d
+  save_env saved_entry
56d25d
+  set prev_saved_entry=
56d25d
+  save_env prev_saved_entry
56d25d
+  set boot_once=true
56d25d
+fi
56d25d
+
56d25d
+function savedefault {
56d25d
+  if [ -z "${boot_once}" ]; then
56d25d
+    saved_entry="${chosen}"
56d25d
+    save_env saved_entry
56d25d
+  fi
56d25d
+}
56d25d
+
56d25d
+function load_video {
56d25d
+  if [ x$feature_all_video_module = xy ]; then
56d25d
+    insmod all_video
56d25d
+  else
56d25d
+    insmod efi_gop
56d25d
+    insmod efi_uga
56d25d
+    insmod ieee1275_fb
56d25d
+    insmod vbe
56d25d
+    insmod vga
56d25d
+    insmod video_bochs
56d25d
+    insmod video_cirrus
56d25d
+  fi
56d25d
+}
56d25d
+
56d25d
+terminal_output console
56d25d
+if [ x$feature_timeout_style = xy ] ; then
56d25d
+  set timeout_style=menu
56d25d
+  set timeout=5
56d25d
+# Fallback normal timeout code in case the timeout_style feature is
56d25d
+# unavailable.
56d25d
+else
56d25d
+  set timeout=5
56d25d
+fi
56d25d
+### END /etc/grub.d/00_header ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/10_linux ###
56d25d
+menuentry 'Fedora, with Linux 3.15.0-0.rc5.git2.10.fc21.x86_64' --class fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.15.0-0.rc5.git2.10.fc21.x86_64-advanced-a14e3dcb-ade3-42f7-832f-d9f66b5ae6a3' {
56d25d
+	load_video
56d25d
+	set gfxpayload=keep
56d25d
+	insmod gzio
56d25d
+	insmod part_msdos
56d25d
+	insmod ext2
56d25d
+	set root='hd0,msdos1'
56d25d
+	if [ x$feature_platform_search_hint = xy ]; then
56d25d
+	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  6169b46f-0257-4319-b2e4-caaed2a8e06b
56d25d
+	else
56d25d
+	  search --no-floppy --fs-uuid --set=root 6169b46f-0257-4319-b2e4-caaed2a8e06b
56d25d
+	fi
56d25d
+	linux16 /vmlinuz-3.15.0-0.rc5.git2.10.fc21.x86_64 root=/dev/mapper/fedora_uefi-root ro  rd.lvm.lv=fedora_uefi/root rd.lvm.lv=fedora_uefi/swap rhgb quiet
56d25d
+}
56d25d
+
56d25d
+### END /etc/grub.d/10_linux ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/20_linux_xen ###
56d25d
+
56d25d
+### END /etc/grub.d/20_linux_xen ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/20_ppc_terminfo ###
56d25d
+### END /etc/grub.d/20_ppc_terminfo ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/30_os-prober ###
56d25d
+### END /etc/grub.d/30_os-prober ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/40_custom ###
56d25d
+# This file provides an easy way to add custom menu entries.  Simply type the
56d25d
+# menu entries you want to add after this comment.  Be careful not to change
56d25d
+# the 'exec tail' line above.
56d25d
+### END /etc/grub.d/40_custom ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/41_custom ###
56d25d
+if [ -f  ${config_directory}/custom.cfg ]; then
56d25d
+  source ${config_directory}/custom.cfg
56d25d
+elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
56d25d
+  source $prefix/custom.cfg;
56d25d
+fi
56d25d
+### END /etc/grub.d/41_custom ###
56d25d
diff --git a/test/results/add/g2-1.14 b/test/results/add/g2-1.14
56d25d
new file mode 100644
56d25d
index 0000000..0865bbc
56d25d
--- /dev/null
56d25d
+++ b/test/results/add/g2-1.14
56d25d
@@ -0,0 +1,126 @@
56d25d
+#
56d25d
+# DO NOT EDIT THIS FILE
56d25d
+#
56d25d
+# It is automatically generated by grub2-mkconfig using templates
56d25d
+# from /etc/grub.d and settings from /etc/default/grub
56d25d
+#
56d25d
+
56d25d
+### BEGIN /etc/grub.d/00_header ###
56d25d
+set pager=1
56d25d
+
56d25d
+if [ -s $prefix/grubenv ]; then
56d25d
+  load_env
56d25d
+fi
56d25d
+if [ "${next_entry}" ] ; then
56d25d
+   set default="${next_entry}"
56d25d
+   set next_entry=
56d25d
+   save_env next_entry
56d25d
+   set boot_once=true
56d25d
+else
56d25d
+   set default="${saved_entry}"
56d25d
+fi
56d25d
+
56d25d
+if [ x"${feature_menuentry_id}" = xy ]; then
56d25d
+  menuentry_id_option="--id"
56d25d
+else
56d25d
+  menuentry_id_option=""
56d25d
+fi
56d25d
+
56d25d
+export menuentry_id_option
56d25d
+
56d25d
+if [ "${prev_saved_entry}" ]; then
56d25d
+  set saved_entry="${prev_saved_entry}"
56d25d
+  save_env saved_entry
56d25d
+  set prev_saved_entry=
56d25d
+  save_env prev_saved_entry
56d25d
+  set boot_once=true
56d25d
+fi
56d25d
+
56d25d
+function savedefault {
56d25d
+  if [ -z "${boot_once}" ]; then
56d25d
+    saved_entry="${chosen}"
56d25d
+    save_env saved_entry
56d25d
+  fi
56d25d
+}
56d25d
+
56d25d
+function load_video {
56d25d
+  if [ x$feature_all_video_module = xy ]; then
56d25d
+    insmod all_video
56d25d
+  else
56d25d
+    insmod efi_gop
56d25d
+    insmod efi_uga
56d25d
+    insmod ieee1275_fb
56d25d
+    insmod vbe
56d25d
+    insmod vga
56d25d
+    insmod video_bochs
56d25d
+    insmod video_cirrus
56d25d
+  fi
56d25d
+}
56d25d
+
56d25d
+terminal_output console
56d25d
+if [ x$feature_timeout_style = xy ] ; then
56d25d
+  set timeout_style=menu
56d25d
+  set timeout=5
56d25d
+# Fallback normal timeout code in case the timeout_style feature is
56d25d
+# unavailable.
56d25d
+else
56d25d
+  set timeout=5
56d25d
+fi
56d25d
+### END /etc/grub.d/00_header ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/10_linux ###
56d25d
+menuentry 'Fedora 21 Rescue' --class fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.15.0-0.rc5.git2.10.fc21.x86_64-advanced-a14e3dcb-ade3-42f7-832f-d9f66b5ae6a3' {
56d25d
+	load_video
56d25d
+	set gfxpayload=keep
56d25d
+	insmod gzio
56d25d
+	insmod part_msdos
56d25d
+	insmod ext2
56d25d
+	set root='hd0,msdos1'
56d25d
+	if [ x$feature_platform_search_hint = xy ]; then
56d25d
+	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  6169b46f-0257-4319-b2e4-caaed2a8e06b
56d25d
+	else
56d25d
+	  search --no-floppy --fs-uuid --set=root 6169b46f-0257-4319-b2e4-caaed2a8e06b
56d25d
+	fi
56d25d
+	linux16 /vmlinuz-0-rescue-5a94251776a14678911d4ae0949500f5 root=/fooooo ro  rd.lvm.lv=fedora_uefi/root rd.lvm.lv=fedora_uefi/swap rhgb quiet
56d25d
+	initrd16 /initramfs-0-rescue-5a94251776a14678911d4ae0949500f5.img
56d25d
+}
56d25d
+menuentry 'Fedora, with Linux 3.15.0-0.rc5.git2.10.fc21.x86_64' --class fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.15.0-0.rc5.git2.10.fc21.x86_64-advanced-a14e3dcb-ade3-42f7-832f-d9f66b5ae6a3' {
56d25d
+	load_video
56d25d
+	set gfxpayload=keep
56d25d
+	insmod gzio
56d25d
+	insmod part_msdos
56d25d
+	insmod ext2
56d25d
+	set root='hd0,msdos1'
56d25d
+	if [ x$feature_platform_search_hint = xy ]; then
56d25d
+	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  6169b46f-0257-4319-b2e4-caaed2a8e06b
56d25d
+	else
56d25d
+	  search --no-floppy --fs-uuid --set=root 6169b46f-0257-4319-b2e4-caaed2a8e06b
56d25d
+	fi
56d25d
+	linux16 /vmlinuz-3.15.0-0.rc5.git2.10.fc21.x86_64 root=/dev/mapper/fedora_uefi-root ro  rd.lvm.lv=fedora_uefi/root rd.lvm.lv=fedora_uefi/swap rhgb quiet
56d25d
+}
56d25d
+
56d25d
+### END /etc/grub.d/10_linux ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/20_linux_xen ###
56d25d
+
56d25d
+### END /etc/grub.d/20_linux_xen ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/20_ppc_terminfo ###
56d25d
+### END /etc/grub.d/20_ppc_terminfo ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/30_os-prober ###
56d25d
+### END /etc/grub.d/30_os-prober ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/40_custom ###
56d25d
+# This file provides an easy way to add custom menu entries.  Simply type the
56d25d
+# menu entries you want to add after this comment.  Be careful not to change
56d25d
+# the 'exec tail' line above.
56d25d
+### END /etc/grub.d/40_custom ###
56d25d
+
56d25d
+### BEGIN /etc/grub.d/41_custom ###
56d25d
+if [ -f  ${config_directory}/custom.cfg ]; then
56d25d
+  source ${config_directory}/custom.cfg
56d25d
+elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
56d25d
+  source $prefix/custom.cfg;
56d25d
+fi
56d25d
+### END /etc/grub.d/41_custom ###
56d25d
-- 
56d25d
2.4.3
56d25d