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

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