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

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