5db4bc7
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5db4bc7
From: Hans de Goede <hdegoede@redhat.com>
5db4bc7
Date: Tue, 26 Nov 2019 09:51:41 +0100
5db4bc7
Subject: [PATCH] grub.d: Fix boot_indeterminate getting set on boot_success=0
5db4bc7
 boot
e602a06
MIME-Version: 1.0
e602a06
Content-Type: text/plain; charset=UTF-8
e602a06
Content-Transfer-Encoding: 8bit
5db4bc7
5db4bc7
The "grub.d: Split out boot success reset from menu auto hide script"
5db4bc7
not only moved the code to clear boot_success and boot_indeterminate
5db4bc7
but for some reason also mixed in some broken changes to the
5db4bc7
boot_indeterminate handling.
5db4bc7
5db4bc7
The boot_indeterminate var is meant to suppress the boot menu after
5db4bc7
a reboot from either a selinux-relabel or offline-updates. These
5db4bc7
2 special boot scenarios do not set boot_success since there is no
5db4bc7
successfull interaction with the user. Instead they increment
5db4bc7
boot_indeterminate, and if it is 1 and only when it is 1, so the
5db4bc7
first reboot after a "special" boot we suppress the menu.
5db4bc7
5db4bc7
To ensure that we do show the menu if we somehow get stuck in a
5db4bc7
"special" boot loop where we do special-boots without them
5db4bc7
incrementing boot_indeterminate, the code before the
5db4bc7
"grub.d: Split out boot success reset from menu auto hide script"
5db4bc7
commit would increment boot_indeterminate once when it is 1, so that
5db4bc7
even if the "special" boot reboot-loop immediately we would show the
5db4bc7
menu on the next boot.
5db4bc7
5db4bc7
That commit broke this however, because it not only moves the code,
5db4bc7
it also changes it from only "incrementing" boot_indeterminate once to
5db4bc7
always incrementing it, except when boot_success == 1 (and we reset it).
5db4bc7
5db4bc7
This broken behavior causes the following problem:
5db4bc7
5db4bc7
1. Boot a broken kernel, system hangs, power-cycle
5db4bc7
2. boot_success now != 1, so we increment boot_indeterminate from 0
5db4bc7
   (unset!) to 1. User either simply tries again, or makes some changes
5db4bc7
   but the end-result still is a system hang, power-cycle
5db4bc7
3. Now boot_indeterminate==1 so we do not show the menu even though the
5db4bc7
   previous boot failed -> BAD
5db4bc7
5db4bc7
This commit fixes this by restoring the behavior of setting
5db4bc7
boot_indeterminate to 2 when it was 1 before.
5db4bc7
5db4bc7
Fixes: "grub.d: Split out boot success reset from menu auto hide script"
5db4bc7
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
e602a06
[jpokorny: 01_menu_auto_hide.in: fix a then/than typo]
e602a06
Signed-off-by: Jan Pokorný <jpokorny@fedoraproject.org>
e602a06
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
5db4bc7
---
5db4bc7
 util/grub.d/10_reset_boot_success.in | 8 ++++----
5db4bc7
 1 file changed, 4 insertions(+), 4 deletions(-)
5db4bc7
5db4bc7
diff --git a/util/grub.d/10_reset_boot_success.in b/util/grub.d/10_reset_boot_success.in
e622855
index 6c88d933dd..e73f4137b3 100644
5db4bc7
--- a/util/grub.d/10_reset_boot_success.in
5db4bc7
+++ b/util/grub.d/10_reset_boot_success.in
5db4bc7
@@ -6,18 +6,18 @@
5db4bc7
 #
5db4bc7
 # The boot_success var needs to be set to 1 from userspace to mark a boot successful.
5db4bc7
 cat << EOF
5db4bc7
-insmod increment
5db4bc7
 # Hiding the menu is ok if last boot was ok or if this is a first boot attempt to boot the entry
5db4bc7
 if [ "\${boot_success}" = "1" -o "\${boot_indeterminate}" = "1" ]; then
5db4bc7
   set menu_hide_ok=1
5db4bc7
 else
5db4bc7
   set menu_hide_ok=0 
5db4bc7
 fi
5db4bc7
-# Reset boot_indeterminate after a successful boot, increment otherwise
5db4bc7
+# Reset boot_indeterminate after a successful boot
5db4bc7
 if [ "\${boot_success}" = "1" ] ; then
5db4bc7
   set boot_indeterminate=0
5db4bc7
-else
5db4bc7
-  increment boot_indeterminate
e602a06
+# Avoid boot_indeterminate causing the menu to be hidden more than once
5db4bc7
+elif [ "\${boot_indeterminate}" = "1" ]; then
5db4bc7
+  set boot_indeterminate=2
5db4bc7
 fi
5db4bc7
 # Reset boot_success for current boot 
5db4bc7
 set boot_success=0