Blame SOURCES/0071-Fix-initial-saved_entry-read-issue-1285601.patch

903092
From 332ec67718959920c26283854ec9280e4023a437 Mon Sep 17 00:00:00 2001
903092
From: Robert Marshall <rmarshall@redhat.com>
903092
Date: Mon, 6 Mar 2017 15:57:54 -0500
903092
Subject: [PATCH] Fix initial saved_entry read issue (#1285601)
903092
903092
If a system has never had a kernel upgrade/rollback then grubby
903092
does not read saved_entry properly.  Added a guard to catch
903092
saved_entry and read it to pick the proper index in these cases.
903092
903092
Resolves: rhbz#1285601
903092
---
903092
 grubby.c | 29 +++++++++++++++++++++++++++--
903092
 1 file changed, 27 insertions(+), 2 deletions(-)
903092
903092
diff --git a/grubby.c b/grubby.c
903092
index de76b56..4d3834b 100644
903092
--- a/grubby.c
903092
+++ b/grubby.c
903092
@@ -2620,6 +2620,9 @@ void setDefaultImage(struct grubConfig *config, int isAddingBootEntry,
903092
 	struct singleEntry *bootEntry, *newDefault;
903092
 	int indexToVerify, firstKernelEntryIndex, currentLookupIndex;
903092
 
903092
+        /* initialize */
903092
+        currentLookupIndex = FIRST_ENTRY_INDEX;
903092
+
903092
 	/* handle the two cases where the user explictly picks the default
903092
 	 * boot entry index as it would exist post-modification */
903092
 
903092
@@ -2685,8 +2688,30 @@ void setDefaultImage(struct grubConfig *config, int isAddingBootEntry,
903092
 			config->defaultImage++;
903092
 		}
903092
 	} else {
903092
-		/* use pre-existing default entry */
903092
-		currentLookupIndex = config->defaultImage;
903092
+                /* check to see if the default is stored in the environment */
903092
+                if (config->defaultImage < FIRST_ENTRY_INDEX) {
903092
+                    if (config->defaultImage == DEFAULT_SAVED || config->defaultImage == DEFAULT_SAVED_GRUB2)
903092
+                    {
903092
+                        if (config->cfi->defaultIsSaved) {
903092
+                            if (config->cfi->getEnv) {
903092
+                                char *defaultTitle = config->cfi->getEnv(config->cfi, "saved_entry");
903092
+
903092
+                                if (defaultTitle) {
903092
+                                    if (isnumber(defaultTitle)) {
903092
+                                        currentLookupIndex = atoi(defaultTitle);
903092
+                                    } else {
903092
+                                        findEntryByTitle(config, defaultTitle, &currentLookupIndex);
903092
+                                    }
903092
+                                    /* set the default Image to an actual index */
903092
+                                    config->defaultImage = currentLookupIndex;
903092
+                                }
903092
+                            }
903092
+                         }
903092
+                    }
903092
+                } else {
903092
+                        /* use pre-existing default entry from the file*/
903092
+                        currentLookupIndex = config->defaultImage;
903092
+                }
903092
 
903092
 		if (isAddingBootEntry
903092
 		    && (newBootEntryIndex <= config->defaultImage)) {
903092
-- 
903092
2.9.3
903092