cca0c4
From d3c64808b6fc4794e2c58b1812315914966afea9 Mon Sep 17 00:00:00 2001
cca0c4
From: Robert Marshall <rmarshall@redhat.com>
cca0c4
Date: Thu, 22 Dec 2016 17:56:44 -0500
cca0c4
Subject: [PATCH 38/55] Write correct default to environment (#1285601)
cca0c4
cca0c4
grubby writes the title of the default boot entry to the bootloader
cca0c4
environment. The title lookup did not correctly account for the offset
cca0c4
required if some boot entries were marked for removal.
cca0c4
cca0c4
Related: rhbz#1285601
cca0c4
---
cca0c4
 grubby.c | 15 ++++++++++++++-
cca0c4
 1 file changed, 14 insertions(+), 1 deletion(-)
cca0c4
cca0c4
diff --git a/grubby.c b/grubby.c
cca0c4
index 692c351ccb6..9edb26d0ded 100644
cca0c4
--- a/grubby.c
cca0c4
+++ b/grubby.c
cca0c4
@@ -1709,7 +1709,20 @@ static void writeDefault(FILE * out, char *indent,
cca0c4
 		fprintf(out, "%sset default=\"${saved_entry}\"\n", indent);
cca0c4
 		if (cfg->defaultImage >= FIRST_ENTRY_INDEX && cfg->cfi->setEnv) {
cca0c4
 			char *title;
cca0c4
-			entry = findEntryByIndex(cfg, cfg->defaultImage);
cca0c4
+			int trueIndex, currentIndex;
cca0c4
+
cca0c4
+			trueIndex = 0;
cca0c4
+			currentIndex = 0;
cca0c4
+
cca0c4
+			while ((entry = findEntryByIndex(cfg, currentIndex))) {
cca0c4
+				if (!entry->skip) {
cca0c4
+					if (trueIndex == cfg->defaultImage) {
cca0c4
+						break;
cca0c4
+					}
cca0c4
+					trueIndex++;
cca0c4
+				}
cca0c4
+				currentIndex++;
cca0c4
+			}
cca0c4
 			line = getLineByType(LT_MENUENTRY, entry->lines);
cca0c4
 			if (!line)
cca0c4
 				line = getLineByType(LT_TITLE, entry->lines);
cca0c4
-- 
cca0c4
2.17.1
cca0c4