From 75bbb85ecacdd014bc2ba54d301d28195f652388 Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Apr 12 2017 10:05:59 +0000 Subject: import grubby-8.28-21.el7_3 --- diff --git a/SOURCES/0061-Rename-setDefaultImage-variables.patch b/SOURCES/0061-Rename-setDefaultImage-variables.patch new file mode 100644 index 0000000..f547282 --- /dev/null +++ b/SOURCES/0061-Rename-setDefaultImage-variables.patch @@ -0,0 +1,66 @@ +From 1b4d2938c4b7cf8d166561214bf12a44c345258d Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Thu, 8 Dec 2016 13:39:22 -0500 +Subject: [PATCH 61/69] Rename setDefaultImage variables + +The variable names in setDefaultImage did not match well with +how they were being used inside the function. Refactored the +variable names as a precursor to refactoring the function. + +Related: rhbz#1285601 +--- + grubby.c | 18 +++++++++--------- + 1 file changed, 9 insertions(+), 9 deletions(-) + +diff --git a/grubby.c b/grubby.c +index ab2c025..344f1da 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -2589,19 +2589,19 @@ void markRemovedImage(struct grubConfig *cfg, const char *image, + entry->skip = 1; + } + +-void setDefaultImage(struct grubConfig *config, int hasNew, +- const char *defaultKernelPath, int newIsDefault, +- const char *prefix, int flags, int index) ++void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath, ++ const char *defaultKernelPath, int newBootEntryIsDefault, ++ const char *prefix, int flags, int newDefaultBootEntryIndex) + { + struct singleEntry *entry, *entry2, *newDefault; + int i, j; + +- if (newIsDefault) { ++ if (newBootEntryIsDefault) { + config->defaultImage = 0; + return; +- } else if ((index >= 0) && config->cfi->defaultIsIndex) { +- if (findEntryByIndex(config, index)) +- config->defaultImage = index; ++ } else if ((newDefaultBootEntryIndex >= 0) && config->cfi->defaultIsIndex) { ++ if (findEntryByIndex(config, newDefaultBootEntryIndex)) ++ config->defaultImage = newDefaultBootEntryIndex; + else + config->defaultImage = -1; + return; +@@ -2629,7 +2629,7 @@ void setDefaultImage(struct grubConfig *config, int hasNew, + + if (entry && !entry->skip) { + /* we can preserve the default */ +- if (hasNew) ++ if (isUserSpecifiedKernelPath) + config->defaultImage++; + + /* count the number of entries erased before this one */ +@@ -2638,7 +2638,7 @@ void setDefaultImage(struct grubConfig *config, int hasNew, + if (entry2->skip) + config->defaultImage--; + } +- } else if (hasNew) { ++ } else if (isUserSpecifiedKernelPath) { + config->defaultImage = 0; + } else { + /* Either we just erased the default (or the default line was bad +-- +2.9.3 + diff --git a/SOURCES/0062-Add-index-constant-definitions-instead-of-open-coded.patch b/SOURCES/0062-Add-index-constant-definitions-instead-of-open-coded.patch new file mode 100644 index 0000000..9b52d9b --- /dev/null +++ b/SOURCES/0062-Add-index-constant-definitions-instead-of-open-coded.patch @@ -0,0 +1,198 @@ +From d1586b86da52810014bd95e46fd5c86a458fca3e Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Tue, 13 Dec 2016 14:36:31 -0500 +Subject: [PATCH 62/69] Add index constant definitions instead of open-coded + values. + +Added numeric constants NO_DEFAULT_ENTRY and FIRST_ENTRY_INDEX. This +clarifies the intent of various assignment operations throughout the +source file. + +Related: rhbz#1285601 +--- + grubby.c | 44 ++++++++++++++++++++++++-------------------- + 1 file changed, 24 insertions(+), 20 deletions(-) + +diff --git a/grubby.c b/grubby.c +index 344f1da..bece23a 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -130,6 +130,10 @@ struct singleEntry { + #define NEED_END (1 << 5) + + #define MAIN_DEFAULT (1 << 0) ++#define FIRST_ENTRY_INDEX 0 /* boot entry index value begin and increment ++ from this initial value */ ++#define NO_DEFAULT_ENTRY -1 /* indicates that no specific default boot ++ entry was set or currently exists */ + #define DEFAULT_SAVED -2 + #define DEFAULT_SAVED_GRUB2 -3 + +@@ -1712,7 +1716,7 @@ static struct grubConfig *readConfig(const char *inName, + *end == ' ' || *end == '\t')) + end++; + if (*end) +- cfg->defaultImage = -1; ++ cfg->defaultImage = NO_DEFAULT_ENTRY; + } else if (defaultLine->numElements == 3) { + char *value = defaultLine->elements[2].item; + while (*value && (*value == '"' || +@@ -1725,7 +1729,7 @@ static struct grubConfig *readConfig(const char *inName, + *end == ' ' || *end == '\t')) + end++; + if (*end) +- cfg->defaultImage = -1; ++ cfg->defaultImage = NO_DEFAULT_ENTRY; + } + } else if (cfi->defaultSupportSaved && + !strncmp(defaultLine->elements[1].item, "saved", +@@ -1735,7 +1739,7 @@ static struct grubConfig *readConfig(const char *inName, + cfg->defaultImage = + strtol(defaultLine->elements[1].item, &end, 10); + if (*end) +- cfg->defaultImage = -1; ++ cfg->defaultImage = NO_DEFAULT_ENTRY; + } else if (defaultLine->numElements >= 2) { + int i = 0; + while ((entry = findEntryByIndex(cfg, i))) { +@@ -1763,7 +1767,7 @@ static struct grubConfig *readConfig(const char *inName, + if (entry) { + cfg->defaultImage = i; + } else { +- cfg->defaultImage = -1; ++ cfg->defaultImage = NO_DEFAULT_ENTRY; + } + } + } else if (cfg->cfi->defaultIsSaved && cfg->cfi->getEnv) { +@@ -1780,7 +1784,7 @@ static struct grubConfig *readConfig(const char *inName, + cfg->defaultImage = index; + } + } else { +- cfg->defaultImage = 0; ++ cfg->defaultImage = FIRST_ENTRY_INDEX; + } + + return cfg; +@@ -1800,7 +1804,7 @@ static void writeDefault(FILE * out, char *indent, + fprintf(out, "%sdefault%ssaved\n", indent, separator); + else if (cfg->cfi->defaultIsSaved) { + fprintf(out, "%sset default=\"${saved_entry}\"\n", indent); +- if (cfg->defaultImage >= 0 && cfg->cfi->setEnv) { ++ if (cfg->defaultImage >= FIRST_ENTRY_INDEX && cfg->cfi->setEnv) { + char *title; + entry = findEntryByIndex(cfg, cfg->defaultImage); + line = getLineByType(LT_MENUENTRY, entry->lines); +@@ -1813,7 +1817,7 @@ static void writeDefault(FILE * out, char *indent, + "saved_entry", title); + } + } +- } else if (cfg->defaultImage > -1) { ++ } else if (cfg->defaultImage >= FIRST_ENTRY_INDEX) { + if (cfg->cfi->defaultIsIndex) { + if (cfg->cfi->defaultIsVariable) { + fprintf(out, "%sset default=\"%d\"\n", indent, +@@ -2515,7 +2519,7 @@ struct singleEntry *findTemplate(struct grubConfig *cfg, const char *prefix, + } + } + } +- } else if (cfg->defaultImage > -1) { ++ } else if (cfg->defaultImage >= FIRST_ENTRY_INDEX) { + entry = findEntryByIndex(cfg, cfg->defaultImage); + if (entry && suitableImage(entry, prefix, skipRemoved, flags)) { + if (indexPtr) +@@ -2597,20 +2601,20 @@ void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath, + int i, j; + + if (newBootEntryIsDefault) { +- config->defaultImage = 0; ++ config->defaultImage = FIRST_ENTRY_INDEX; + return; + } else if ((newDefaultBootEntryIndex >= 0) && config->cfi->defaultIsIndex) { + if (findEntryByIndex(config, newDefaultBootEntryIndex)) + config->defaultImage = newDefaultBootEntryIndex; + else +- config->defaultImage = -1; ++ config->defaultImage = NO_DEFAULT_ENTRY; + return; + } else if (defaultKernelPath) { + i = 0; + if (findEntryByPath(config, defaultKernelPath, prefix, &i)) { + config->defaultImage = i; + } else { +- config->defaultImage = -1; ++ config->defaultImage = NO_DEFAULT_ENTRY; + return; + } + } +@@ -2622,7 +2626,7 @@ void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath, + /* default is set to saved, we don't want to change it */ + return; + +- if (config->defaultImage > -1) ++ if (config->defaultImage >= FIRST_ENTRY_INDEX) + entry = findEntryByIndex(config, config->defaultImage); + else + entry = NULL; +@@ -2639,7 +2643,7 @@ void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath, + config->defaultImage--; + } + } else if (isUserSpecifiedKernelPath) { +- config->defaultImage = 0; ++ config->defaultImage = FIRST_ENTRY_INDEX; + } else { + /* Either we just erased the default (or the default line was bad + * to begin with) and didn't put a new one in. We'll use the first +@@ -2648,7 +2652,7 @@ void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath, + findTemplate(config, prefix, &config->defaultImage, 1, + flags); + if (!newDefault) +- config->defaultImage = -1; ++ config->defaultImage = NO_DEFAULT_ENTRY; + } + } + +@@ -5210,11 +5214,11 @@ int main(int argc, const char **argv) + struct singleEntry *entry; + char *rootspec; + +- if (config->defaultImage == -1) ++ if (config->defaultImage == NO_DEFAULT_ENTRY) + return 0; + if (config->defaultImage == DEFAULT_SAVED_GRUB2 && + cfi->defaultIsSaved) +- config->defaultImage = 0; ++ config->defaultImage = FIRST_ENTRY_INDEX; + entry = findEntryByIndex(config, config->defaultImage); + if (!entry) + return 0; +@@ -5237,11 +5241,11 @@ int main(int argc, const char **argv) + struct singleLine *line; + struct singleEntry *entry; + +- if (config->defaultImage == -1) ++ if (config->defaultImage == NO_DEFAULT_ENTRY) + return 0; + if (config->defaultImage == DEFAULT_SAVED_GRUB2 && + cfi->defaultIsSaved) +- config->defaultImage = 0; ++ config->defaultImage = FIRST_ENTRY_INDEX; + entry = findEntryByIndex(config, config->defaultImage); + if (!entry) + return 0; +@@ -5271,11 +5275,11 @@ int main(int argc, const char **argv) + return 0; + + } else if (displayDefaultIndex) { +- if (config->defaultImage == -1) ++ if (config->defaultImage == NO_DEFAULT_ENTRY) + return 0; + if (config->defaultImage == DEFAULT_SAVED_GRUB2 && + cfi->defaultIsSaved) +- config->defaultImage = 0; ++ config->defaultImage = FIRST_ENTRY_INDEX; + printf("%i\n", config->defaultImage); + return 0; + +-- +2.9.3 + diff --git a/SOURCES/0063-Track-configuration-modifications.patch b/SOURCES/0063-Track-configuration-modifications.patch new file mode 100644 index 0000000..8766729 --- /dev/null +++ b/SOURCES/0063-Track-configuration-modifications.patch @@ -0,0 +1,50 @@ +From db71a9ef9363f9ce01ee1746c827f8a2feac73e7 Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Thu, 8 Dec 2016 16:52:45 -0500 +Subject: [PATCH 63/69] Track configuration modifications + +The setDefaultImage function had a subtle dependency on being run before +addNewKernel is invoked. Added the ability to track invocation to +prevent them from being so tightly coupled. + +Related: rhbz#1285601 +--- + grubby.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/grubby.c b/grubby.c +index bece23a..3929212 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -671,6 +671,8 @@ struct grubConfig { + int fallbackImage; /* just like defaultImage */ + int flags; + struct configFileInfo *cfi; ++ int isModified; /* assumes only one entry added ++ per invocation of grubby */ + }; + + blkid_cache blkid; +@@ -1399,6 +1401,7 @@ static struct grubConfig *readConfig(const char *inName, + cfg->theLines = NULL; + cfg->entries = NULL; + cfg->fallbackImage = 0; ++ cfg->isModified = 0; + + /* copy everything we have */ + while (*head) { +@@ -4764,8 +4767,10 @@ int addNewKernel(struct grubConfig *config, struct singleEntry *template, + } + + if (updateImage(config, indexs, prefix, newKernelArgs, NULL, +- newMBKernelArgs, NULL)) ++ newMBKernelArgs, NULL)) { ++ config->isModified = 1; + return 1; ++ } + + return 0; + } +-- +2.9.3 + diff --git a/SOURCES/0064-Fix-some-test-cases-where-the-resulting-default-inde.patch b/SOURCES/0064-Fix-some-test-cases-where-the-resulting-default-inde.patch new file mode 100644 index 0000000..b127d11 --- /dev/null +++ b/SOURCES/0064-Fix-some-test-cases-where-the-resulting-default-inde.patch @@ -0,0 +1,65 @@ +From 2b4b56143e6af082263cf28ecbd3ff049d697a7f Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Thu, 15 Dec 2016 21:47:28 -0500 +Subject: [PATCH 64/69] Fix some test cases where the resulting default index + is wrong + +Fix two issues with tests where removing a kernel or adding a boot entry +at a user specified index had the wrong default index selected in the +expected output. + +One of these issues is the --set-index test cases for grub 1, which +expect --make-default is implied where it should not be. + +The third is a removal test, where the default index in the result data +is off by one when we've removed 2 entries keyed off of the kernel +filesystem path. + +This change causes these test cases to fail. + +Resolves: rhbz#1285601 +--- + test/results/add/g1.17 | 2 +- + test/results/add/g1.9 | 2 +- + test/results/remove/g7.1 | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/test/results/add/g1.17 b/test/results/add/g1.17 +index 6a38822..eda4e93 100644 +--- a/test/results/add/g1.17 ++++ b/test/results/add/g1.17 +@@ -7,7 +7,7 @@ + # kernel /vmlinuz-version ro root=/dev/sda1 + # initrd /initrd-version.img + #boot=/dev/hda +-default=1 ++default=0 + timeout=10 + splashimage=(hd0,0)/grub/splash.xpm.gz + title Red Hat Linux (2.4.7-2) +diff --git a/test/results/add/g1.9 b/test/results/add/g1.9 +index 310623d..8976e76 100644 +--- a/test/results/add/g1.9 ++++ b/test/results/add/g1.9 +@@ -7,7 +7,7 @@ + # kernel /vmlinuz-version ro root=/dev/sda1 + # initrd /initrd-version.img + #boot=/dev/hda +-default=2 ++default=1 + timeout=10 + splashimage=(hd0,0)/grub/splash.xpm.gz + title Red Hat Linux (2.4.7-2) +diff --git a/test/results/remove/g7.1 b/test/results/remove/g7.1 +index ea1a6fb..611d7a1 100644 +--- a/test/results/remove/g7.1 ++++ b/test/results/remove/g7.1 +@@ -1,4 +1,4 @@ +-default=1 ++default=0 + timeout=10 + splashimage=(hd0,5)/boot/grub/splash.xpm.gz + +-- +2.9.3 + diff --git a/SOURCES/0065-Don-t-assume-make-default-just-because-set-index-was.patch b/SOURCES/0065-Don-t-assume-make-default-just-because-set-index-was.patch new file mode 100644 index 0000000..6d3292a --- /dev/null +++ b/SOURCES/0065-Don-t-assume-make-default-just-because-set-index-was.patch @@ -0,0 +1,196 @@ +From 0343d901cade475b6b92134cd45184316d80039f Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Tue, 13 Dec 2016 18:20:15 -0500 +Subject: [PATCH 65/69] Don't assume --make-default just because --set-index + was passed. + +grubby previously made the assumption that every time a new +boot entry gets added using --set-index, it should be the default. Due +to this behavior, it also masked an logic error that prevented the +selection of the proper index in cases where it was necessary to +dynamically pick a new default boot entry, or to keep the existing +default boot entry when its position in the config file moved. + +Resolves: rhbz#1285601 +--- + grubby.c | 136 ++++++++++++++++++++++++++++++++++++++++++++------------------- + 1 file changed, 96 insertions(+), 40 deletions(-) + +diff --git a/grubby.c b/grubby.c +index 3929212..4e872c0 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -2596,66 +2596,121 @@ void markRemovedImage(struct grubConfig *cfg, const char *image, + entry->skip = 1; + } + +-void setDefaultImage(struct grubConfig *config, int isUserSpecifiedKernelPath, ++void setDefaultImage(struct grubConfig *config, int isAddingBootEntry, + const char *defaultKernelPath, int newBootEntryIsDefault, +- const char *prefix, int flags, int newDefaultBootEntryIndex) ++ const char *prefix, int flags, ++ int newDefaultBootEntryIndex, int newBootEntryIndex) + { +- struct singleEntry *entry, *entry2, *newDefault; +- int i, j; ++ struct singleEntry *bootEntry, *newDefault; ++ int indexToVerify, firstKernelEntryIndex, currentLookupIndex; ++ ++ /* handle the two cases where the user explictly picks the default ++ * boot entry index as it would exist post-modification */ + ++ /* Case 1: user chose to make the latest boot entry the default */ + if (newBootEntryIsDefault) { +- config->defaultImage = FIRST_ENTRY_INDEX; ++ config->defaultImage = newBootEntryIndex; + return; +- } else if ((newDefaultBootEntryIndex >= 0) && config->cfi->defaultIsIndex) { +- if (findEntryByIndex(config, newDefaultBootEntryIndex)) ++ } ++ ++ /* Case 2: user picked an arbitrary index as the default boot entry */ ++ if (newDefaultBootEntryIndex >= FIRST_ENTRY_INDEX ++ && config->cfi->defaultIsIndex) { ++ indexToVerify = newDefaultBootEntryIndex; ++ ++ /* user chose to make latest boot entry the default */ ++ if (newDefaultBootEntryIndex == newBootEntryIndex) { ++ config->defaultImage = newBootEntryIndex; ++ return; ++ } ++ ++ /* the user picks the default index based on the ++ * order of the bootloader configuration after ++ * modification; ensure we are checking for the ++ * existence of the correct entry */ ++ if (newBootEntryIndex < newDefaultBootEntryIndex) { ++ if (!config->isModified) ++ indexToVerify--; ++ } ++ ++ /* verify the user selected index will exist */ ++ if (findEntryByIndex(config, indexToVerify)) { + config->defaultImage = newDefaultBootEntryIndex; +- else ++ } else { + config->defaultImage = NO_DEFAULT_ENTRY; ++ } ++ + return; +- } else if (defaultKernelPath) { +- i = 0; +- if (findEntryByPath(config, defaultKernelPath, prefix, &i)) { +- config->defaultImage = i; +- } else { ++ } ++ ++ /* handle cases where the index value may shift */ ++ ++ /* check validity of existing default or first-entry-found ++ selection */ ++ if (defaultKernelPath) { ++ /* user requested first-entry-found */ ++ if (!findEntryByPath(config, defaultKernelPath, ++ prefix, &firstKernelEntryIndex)) { ++ /* don't change default if can't find match */ + config->defaultImage = NO_DEFAULT_ENTRY; + return; + } +- } + +- /* defaultImage now points to what we'd like to use, but before any order +- changes */ +- if ((config->defaultImage == DEFAULT_SAVED) || +- (config->defaultImage == DEFAULT_SAVED_GRUB2)) +- /* default is set to saved, we don't want to change it */ +- return; ++ config->defaultImage = firstKernelEntryIndex; + +- if (config->defaultImage >= FIRST_ENTRY_INDEX) +- entry = findEntryByIndex(config, config->defaultImage); +- else +- entry = NULL; ++ /* this is where we start looking for decrement later */ ++ currentLookupIndex = config->defaultImage; + +- if (entry && !entry->skip) { +- /* we can preserve the default */ +- if (isUserSpecifiedKernelPath) ++ if (isAddingBootEntry && !config->isModified && ++ (newBootEntryIndex < config->defaultImage)) { ++ /* increment because new entry added before default */ + config->defaultImage++; +- +- /* count the number of entries erased before this one */ +- for (j = 0; j < config->defaultImage; j++) { +- entry2 = findEntryByIndex(config, j); +- if (entry2->skip) +- config->defaultImage--; + } +- } else if (isUserSpecifiedKernelPath) { +- config->defaultImage = FIRST_ENTRY_INDEX; + } else { +- /* Either we just erased the default (or the default line was bad +- * to begin with) and didn't put a new one in. We'll use the first +- * valid image. */ ++ /* use pre-existing default entry */ ++ currentLookupIndex = config->defaultImage; ++ ++ if (isAddingBootEntry ++ && (newBootEntryIndex <= config->defaultImage)) { ++ config->defaultImage++; ++ ++ if (config->isModified) { ++ currentLookupIndex++; ++ } ++ } ++ } ++ ++ /* sanity check - is this entry index valid? */ ++ bootEntry = findEntryByIndex(config, currentLookupIndex); ++ ++ if ((bootEntry && bootEntry->skip) || !bootEntry) { ++ /* entry is to be skipped or is invalid */ ++ if (isAddingBootEntry) { ++ config->defaultImage = newBootEntryIndex; ++ return; ++ } + newDefault = + findTemplate(config, prefix, &config->defaultImage, 1, + flags); +- if (!newDefault) ++ if (!newDefault) { + config->defaultImage = NO_DEFAULT_ENTRY; ++ } ++ ++ return; ++ } ++ ++ currentLookupIndex--; ++ ++ /* decrement index by the total number of entries deleted */ ++ ++ for (indexToVerify = currentLookupIndex; ++ indexToVerify >= FIRST_ENTRY_INDEX; indexToVerify--) { ++ ++ bootEntry = findEntryByIndex(config, indexToVerify); ++ ++ if (bootEntry && bootEntry->skip) { ++ config->defaultImage--; ++ } + } + } + +@@ -5300,7 +5355,8 @@ int main(int argc, const char **argv) + markRemovedImage(config, removeKernelPath, bootPrefix); + markRemovedImage(config, removeMBKernel, bootPrefix); + setDefaultImage(config, newKernelPath != NULL, defaultKernel, +- makeDefault, bootPrefix, flags, defaultIndex); ++ makeDefault, bootPrefix, flags, defaultIndex, ++ newIndex); + setFallbackImage(config, newKernelPath != NULL); + if (updateImage(config, updateKernelPath, bootPrefix, newKernelArgs, + removeArgs, newMBKernelArgs, removeMBKernelArgs)) +-- +2.9.3 + diff --git a/SOURCES/0066-Clarify-set-default-index-in-the-man-page.patch b/SOURCES/0066-Clarify-set-default-index-in-the-man-page.patch new file mode 100644 index 0000000..0630d86 --- /dev/null +++ b/SOURCES/0066-Clarify-set-default-index-in-the-man-page.patch @@ -0,0 +1,32 @@ +From 778ec42a36c02da40fd6044ac42fdee0e186c7fc Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Thu, 15 Dec 2016 21:53:31 -0500 +Subject: [PATCH 66/69] Clarify --set-default-index in the man page. + +This changes the man page to say that the index value provided with +--set-default-index applies to the boot entry list after modifications. + +Resolves: rhbz#1285601 +--- + grubby.8 | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/grubby.8 b/grubby.8 +index 7789b9a..465df32 100644 +--- a/grubby.8 ++++ b/grubby.8 +@@ -144,8 +144,9 @@ boot entry. This may not be invoked with \fB-\-set-default-index\fR. + + .TP + \fB-\-set-default-index\fR=\fIentry-index\fR +-Makes the given entry number the default boot entry. This may not +-be invoked with \fB-\-set-default\fR. ++Makes the given entry number the default boot entry. This may not be invoked ++with \fB-\-set-default\fR. The given value represents the index in the ++post-modification boot entry list. + + .TP + \fB-\-make-default\fR +-- +2.9.3 + diff --git a/SOURCES/0067-Add-multi-entry-removal-test-1285601.patch b/SOURCES/0067-Add-multi-entry-removal-test-1285601.patch new file mode 100644 index 0000000..473c610 --- /dev/null +++ b/SOURCES/0067-Add-multi-entry-removal-test-1285601.patch @@ -0,0 +1,261 @@ +From ef74333dffe359aa5cf9ea1313ab9ccb7ed3b192 Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Thu, 22 Dec 2016 17:40:52 -0500 +Subject: [PATCH 67/69] Add multi-entry removal test (#1285601) + +Test what happens to the default entry set in the grub environment after +removing the first two boot entries. + +Related: rhbz#1285601 +--- + test.sh | 7 +++ + test/grub2-support_files/grubenv.4 | 3 + + test/grub2.19 | 112 +++++++++++++++++++++++++++++++++++++ + test/results/remove/g2.19 | 88 +++++++++++++++++++++++++++++ + 4 files changed, 210 insertions(+) + create mode 100644 test/grub2-support_files/grubenv.4 + create mode 100644 test/grub2.19 + create mode 100644 test/results/remove/g2.19 + +diff --git a/test.sh b/test.sh +index dbf7507..3631ed0 100755 +--- a/test.sh ++++ b/test.sh +@@ -570,6 +570,13 @@ if [ "$testgrub2" == "y" ]; then + --copy-default --title 'Red Hat Enterprise Linux Server' \ + --args=root=/dev/mapper/foo-- + ++ grub2Test grub2.19 remove/g2.19 --env grubenv.4 \ ++ --remove-kernel=/boot/vmlinuz-2.6.38.2-9.fc15.x86_64 \ ++ --boot-filesystem=/boot/ ++ commandTest "saved_default output" \ ++ "grub2-editenv test/grub2-support_files/env_temp list" \ ++ "saved_entry=Linux, with Fedora 2.6.38.8-32.fc15.x86_64" ++ + # copy a stanza and add arguments as well, while using --set-index= + testing="GRUB2 add stanza and new args with --set-index=" + grub2Test grub2.18 add/g2-1.18 --env grubenv.3 \ +diff --git a/test/grub2-support_files/grubenv.4 b/test/grub2-support_files/grubenv.4 +new file mode 100644 +index 0000000..1311638 +--- /dev/null ++++ b/test/grub2-support_files/grubenv.4 +@@ -0,0 +1,3 @@ ++# GRUB Environment Block ++saved_entry=Linux, with Fedora 2.6.38.8-32.fc15.x86_64 ++################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################ +diff --git a/test/grub2.19 b/test/grub2.19 +new file mode 100644 +index 0000000..be07b3e +--- /dev/null ++++ b/test/grub2.19 +@@ -0,0 +1,112 @@ ++# ++# DO NOT EDIT THIS FILE ++# ++# It is automatically generated by grub2-mkconfig using templates ++# from /etc/grub.d and settings from /etc/default/grub ++# ++ ++### BEGIN /etc/grub.d/00_header ### ++if [ -s $prefix/grubenv ]; then ++ load_env ++fi ++if [ "${next_entry}" ] ; then ++ set default="${next_entry}" ++ set next_entry= ++ save_env next_entry ++ set boot_once=true ++else ++ set default="${saved_entry}" ++fi ++ ++if [ x"${feature_menuentry_id}" = xy ]; then ++ menuentry_id_option="--id" ++else ++ menuentry_id_option="" ++fi ++ ++export menuentry_id_option ++ ++if [ "${prev_saved_entry}" ]; then ++ set saved_entry="${prev_saved_entry}" ++ save_env saved_entry ++ set prev_saved_entry= ++ save_env prev_saved_entry ++ set boot_once=true ++fi ++ ++function savedefault { ++ if [ -z "${boot_once}" ]; then ++ saved_entry="${chosen}" ++ save_env saved_entry ++ fi ++} ++ ++function load_video { ++ insmod vbe ++ insmod vga ++ insmod video_bochs ++ insmod video_cirrus ++} ++ ++set timeout=5 ++### END /etc/grub.d/00_header ### ++ ++### BEGIN /etc/grub.d/10_linux ### ++menuentry 'First Title To Remove' --class gnu-linux --class gnu --class os { ++ load_video ++ set gfxpayload=keep ++ insmod part_msdos ++ insmod ext2 ++ set root='(hd0,msdos1)' ++ search --no-floppy --fs-uuid --set=root df0170c9-7d05-415c-bbd1-d4d503ba0eed ++ echo 'Loading Linux 2.6.38.2-9.fc15.x86_64 ...' ++ linux /vmlinuz-2.6.38.2-9.fc15.x86_64 root=/dev/mapper/vg_pjones5-lv_root ro quiet rhgb ++ echo 'Loading initial ramdisk ...' ++ initrd /initramfs-2.6.38.2-9.fc15.x86_64.img ++} ++menuentry 'Second Title To Remove' --class gnu-linux --class gnu --class os { ++ load_video ++ set gfxpayload=keep ++ insmod part_msdos ++ insmod ext2 ++ set root='(hd0,msdos1)' ++ search --no-floppy --fs-uuid --set=root df0170c9-7d05-415c-bbd1-d4d503ba0eed ++ echo 'Loading Linux 2.6.38.2-9.fc15.x86_64 ...' ++ linux /vmlinuz-2.6.38.2-9.fc15.x86_64 root=/dev/mapper/vg_pjones5-lv_root ro quiet rhgb ++ echo 'Loading initial ramdisk ...' ++ initrd /initramfs-2.6.38.2-9.fc15.x86_64.img ++} ++menuentry 'Linux, with Fedora 2.6.38.8-32.fc15.x86_64' --class gnu-linux --class gnu --class os { ++ load_video ++ set gfxpayload=keep ++ insmod part_msdos ++ insmod ext2 ++ set root='(hd0,msdos1)' ++ search --no-floppy --fs-uuid --set=root df0170c9-7d05-415c-bbd1-d4d503ba0eed ++ echo 'Loading Fedora 2.6.38.8-32.fc15.x86_64 ...' ++ linux /vmlinuz-2.6.38.8-32.fc15.x86_64 root=/dev/mapper/vg_pjones5-lv_root ro quiet rhgb ++ echo 'Loading initial ramdisk ...' ++ initrd /initramfs-2.6.38.8-32.fc15.x86_64.img ++} ++### END /etc/grub.d/10_linux ### ++ ++### BEGIN /etc/grub.d/20_linux_xen ### ++### END /etc/grub.d/20_linux_xen ### ++ ++### BEGIN /etc/grub.d/30_os-prober ### ++### END /etc/grub.d/30_os-prober ### ++ ++### BEGIN /etc/grub.d/40_custom ### ++# This file provides an easy way to add custom menu entries. Simply type the ++# menu entries you want to add after this comment. Be careful not to change ++# the 'exec tail' line above. ++### END /etc/grub.d/40_custom ### ++ ++### BEGIN /etc/grub.d/41_custom ### ++if [ -f $prefix/custom.cfg ]; then ++ source $prefix/custom.cfg; ++fi ++### END /etc/grub.d/41_custom ### ++ ++### BEGIN /etc/grub.d/90_persistent ### ++### END /etc/grub.d/90_persistent ### +diff --git a/test/results/remove/g2.19 b/test/results/remove/g2.19 +new file mode 100644 +index 0000000..f65edd5 +--- /dev/null ++++ b/test/results/remove/g2.19 +@@ -0,0 +1,88 @@ ++# ++# DO NOT EDIT THIS FILE ++# ++# It is automatically generated by grub2-mkconfig using templates ++# from /etc/grub.d and settings from /etc/default/grub ++# ++ ++### BEGIN /etc/grub.d/00_header ### ++if [ -s $prefix/grubenv ]; then ++ load_env ++fi ++if [ "${next_entry}" ] ; then ++ set default="${next_entry}" ++ set next_entry= ++ save_env next_entry ++ set boot_once=true ++else ++ set default="${saved_entry}" ++fi ++ ++if [ x"${feature_menuentry_id}" = xy ]; then ++ menuentry_id_option="--id" ++else ++ menuentry_id_option="" ++fi ++ ++export menuentry_id_option ++ ++if [ "${prev_saved_entry}" ]; then ++ set saved_entry="${prev_saved_entry}" ++ save_env saved_entry ++ set prev_saved_entry= ++ save_env prev_saved_entry ++ set boot_once=true ++fi ++ ++function savedefault { ++ if [ -z "${boot_once}" ]; then ++ saved_entry="${chosen}" ++ save_env saved_entry ++ fi ++} ++ ++function load_video { ++ insmod vbe ++ insmod vga ++ insmod video_bochs ++ insmod video_cirrus ++} ++ ++set timeout=5 ++### END /etc/grub.d/00_header ### ++ ++### BEGIN /etc/grub.d/10_linux ### ++menuentry 'Linux, with Fedora 2.6.38.8-32.fc15.x86_64' --class gnu-linux --class gnu --class os { ++ load_video ++ set gfxpayload=keep ++ insmod part_msdos ++ insmod ext2 ++ set root='(hd0,msdos1)' ++ search --no-floppy --fs-uuid --set=root df0170c9-7d05-415c-bbd1-d4d503ba0eed ++ echo 'Loading Fedora 2.6.38.8-32.fc15.x86_64 ...' ++ linux /vmlinuz-2.6.38.8-32.fc15.x86_64 root=/dev/mapper/vg_pjones5-lv_root ro quiet rhgb ++ echo 'Loading initial ramdisk ...' ++ initrd /initramfs-2.6.38.8-32.fc15.x86_64.img ++} ++### END /etc/grub.d/10_linux ### ++ ++### BEGIN /etc/grub.d/20_linux_xen ### ++### END /etc/grub.d/20_linux_xen ### ++ ++### BEGIN /etc/grub.d/30_os-prober ### ++### END /etc/grub.d/30_os-prober ### ++ ++### BEGIN /etc/grub.d/40_custom ### ++# This file provides an easy way to add custom menu entries. Simply type the ++# menu entries you want to add after this comment. Be careful not to change ++# the 'exec tail' line above. ++### END /etc/grub.d/40_custom ### ++ ++### BEGIN /etc/grub.d/41_custom ### ++if [ -f $prefix/custom.cfg ]; then ++ source $prefix/custom.cfg; ++fi ++### END /etc/grub.d/41_custom ### ++ ++### BEGIN /etc/grub.d/90_persistent ### ++### END /etc/grub.d/90_persistent ### +-- +2.9.3 + diff --git a/SOURCES/0068-Fix-findTemplate-index-logic-1285601.patch b/SOURCES/0068-Fix-findTemplate-index-logic-1285601.patch new file mode 100644 index 0000000..eeb03d4 --- /dev/null +++ b/SOURCES/0068-Fix-findTemplate-index-logic-1285601.patch @@ -0,0 +1,40 @@ +From 3d6e04814d4578a4f57cfc98709ec0640428977e Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Thu, 22 Dec 2016 17:52:14 -0500 +Subject: [PATCH 68/69] Fix findTemplate index logic (#1285601) + +The fallback case where findTemplate has to look for the first entry +contained a logic flaw that could return an incorrect index. This +discovered index should be reduced by one for each boot entry that will +be skipped in the final output. The flaw occurred because the index +variable was used for the loop upper bound at the same time as it was +being decremented within the actual loop body. The loop would thus fail +to examine a number of boot entries equal to the total number of +iterations the loop performed. + +Related: rhbz#1285601 +--- + grubby.c | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/grubby.c b/grubby.c +index 4e872c0..57c1ed7 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -2534,8 +2534,11 @@ struct singleEntry *findTemplate(struct grubConfig *cfg, const char *prefix, + index = 0; + while ((entry = findEntryByIndex(cfg, index))) { + if (suitableImage(entry, prefix, skipRemoved, flags)) { +- int j; +- for (j = 0; j < index; j++) { ++ int j, unmodifiedIndex; ++ ++ unmodifiedIndex = index; ++ ++ for (j = 0; j < unmodifiedIndex; j++) { + entry2 = findEntryByIndex(cfg, j); + if (entry2->skip) + index--; +-- +2.9.3 + diff --git a/SOURCES/0069-Write-correct-default-to-environment-1285601.patch b/SOURCES/0069-Write-correct-default-to-environment-1285601.patch new file mode 100644 index 0000000..3c32338 --- /dev/null +++ b/SOURCES/0069-Write-correct-default-to-environment-1285601.patch @@ -0,0 +1,43 @@ +From 23355786a334e05a99b60b6c7769665ffeb3bdc4 Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Thu, 22 Dec 2016 17:56:44 -0500 +Subject: [PATCH 69/69] Write correct default to environment (#1285601) + +grubby writes the title of the default boot entry to the bootloader +environment. The title lookup did not correctly account for the offset +required if some boot entries were marked for removal. + +Related: rhbz#1285601 +--- + grubby.c | 15 ++++++++++++++- + 1 file changed, 14 insertions(+), 1 deletion(-) + +diff --git a/grubby.c b/grubby.c +index 57c1ed7..9d9d748 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -1809,7 +1809,20 @@ static void writeDefault(FILE * out, char *indent, + fprintf(out, "%sset default=\"${saved_entry}\"\n", indent); + if (cfg->defaultImage >= FIRST_ENTRY_INDEX && cfg->cfi->setEnv) { + char *title; +- entry = findEntryByIndex(cfg, cfg->defaultImage); ++ int trueIndex, currentIndex; ++ ++ trueIndex = 0; ++ currentIndex = 0; ++ ++ while ((entry = findEntryByIndex(cfg, currentIndex))) { ++ if (!entry->skip) { ++ if (trueIndex == cfg->defaultImage) { ++ break; ++ } ++ trueIndex++; ++ } ++ currentIndex++; ++ } + line = getLineByType(LT_MENUENTRY, entry->lines); + if (!line) + line = getLineByType(LT_TITLE, entry->lines); +-- +2.9.3 + diff --git a/SOURCES/0070-Initialize-variable-for-ppc-environment-1285601.patch b/SOURCES/0070-Initialize-variable-for-ppc-environment-1285601.patch new file mode 100644 index 0000000..0d8badc --- /dev/null +++ b/SOURCES/0070-Initialize-variable-for-ppc-environment-1285601.patch @@ -0,0 +1,29 @@ +From 7f4bde0a1c7889f088c704d441323fefd12acffc Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Mon, 27 Feb 2017 15:59:53 -0500 +Subject: [PATCH] Initialize variable for ppc environment (#1285601) + +Building on PPC does not default the value of an uninitialized integer +to zero which caused test failures. + +Related: rhbz#1285601 +--- + grubby.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/grubby.c b/grubby.c +index 9544212..7cd5c90 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -2259,6 +2259,8 @@ void setDefaultImage(struct grubConfig *config, int isAddingBootEntry, + /* check validity of existing default or first-entry-found + selection */ + if (defaultKernelPath) { ++ /* we must initialize this */ ++ firstKernelEntryIndex = 0; + /* user requested first-entry-found */ + if (!findEntryByPath(config, defaultKernelPath, + prefix, &firstKernelEntryIndex)) { +-- +2.9.3 + diff --git a/SOURCES/0071-Fix-initial-saved_entry-read-issue-1285601.patch b/SOURCES/0071-Fix-initial-saved_entry-read-issue-1285601.patch new file mode 100644 index 0000000..51df2da --- /dev/null +++ b/SOURCES/0071-Fix-initial-saved_entry-read-issue-1285601.patch @@ -0,0 +1,64 @@ +From 332ec67718959920c26283854ec9280e4023a437 Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Mon, 6 Mar 2017 15:57:54 -0500 +Subject: [PATCH] Fix initial saved_entry read issue (#1285601) + +If a system has never had a kernel upgrade/rollback then grubby +does not read saved_entry properly. Added a guard to catch +saved_entry and read it to pick the proper index in these cases. + +Resolves: rhbz#1285601 +--- + grubby.c | 29 +++++++++++++++++++++++++++-- + 1 file changed, 27 insertions(+), 2 deletions(-) + +diff --git a/grubby.c b/grubby.c +index de76b56..4d3834b 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -2620,6 +2620,9 @@ void setDefaultImage(struct grubConfig *config, int isAddingBootEntry, + struct singleEntry *bootEntry, *newDefault; + int indexToVerify, firstKernelEntryIndex, currentLookupIndex; + ++ /* initialize */ ++ currentLookupIndex = FIRST_ENTRY_INDEX; ++ + /* handle the two cases where the user explictly picks the default + * boot entry index as it would exist post-modification */ + +@@ -2685,8 +2688,30 @@ void setDefaultImage(struct grubConfig *config, int isAddingBootEntry, + config->defaultImage++; + } + } else { +- /* use pre-existing default entry */ +- currentLookupIndex = config->defaultImage; ++ /* check to see if the default is stored in the environment */ ++ if (config->defaultImage < FIRST_ENTRY_INDEX) { ++ if (config->defaultImage == DEFAULT_SAVED || config->defaultImage == DEFAULT_SAVED_GRUB2) ++ { ++ if (config->cfi->defaultIsSaved) { ++ if (config->cfi->getEnv) { ++ char *defaultTitle = config->cfi->getEnv(config->cfi, "saved_entry"); ++ ++ if (defaultTitle) { ++ if (isnumber(defaultTitle)) { ++ currentLookupIndex = atoi(defaultTitle); ++ } else { ++ findEntryByTitle(config, defaultTitle, ¤tLookupIndex); ++ } ++ /* set the default Image to an actual index */ ++ config->defaultImage = currentLookupIndex; ++ } ++ } ++ } ++ } ++ } else { ++ /* use pre-existing default entry from the file*/ ++ currentLookupIndex = config->defaultImage; ++ } + + if (isAddingBootEntry + && (newBootEntryIndex <= config->defaultImage)) { +-- +2.9.3 + diff --git a/SOURCES/0072-Add-s390-s390x-info-test-1285601.patch b/SOURCES/0072-Add-s390-s390x-info-test-1285601.patch new file mode 100644 index 0000000..1d9a579 --- /dev/null +++ b/SOURCES/0072-Add-s390-s390x-info-test-1285601.patch @@ -0,0 +1,74 @@ +From 70e36b1a4e67a162c44a692bcde6bec6b6bdc9ee Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Tue, 14 Mar 2017 22:55:27 -0400 +Subject: [PATCH 72/75] Add s390/s390x --info test (#1285601) + +Running the --info grubby option on s390/s390x platforms always returned +the (null) value. Added a test to look at --info and ensure it comes out +as a user would expect. + +Resolves: rhbz#1285601 +--- + test.sh | 2 ++ + test/results/info/z2.1 | 6 ++++++ + test/zipl.2 | 22 ++++++++++++++++++++++ + 3 files changed, 30 insertions(+) + create mode 100644 test/results/info/z2.1 + create mode 100644 test/zipl.2 + +diff --git a/test.sh b/test.sh +index 3631ed0..34ba4d7 100755 +--- a/test.sh ++++ b/test.sh +@@ -320,6 +320,8 @@ testing="Z/IPL display default title" + ziplDisplayTest zipl.1 defaulttitle/z.1 --default-title + testing="Z/IPL display default kernel" + ziplDisplayTest zipl.1 defaultkernel/z.1 --default-kernel ++testing="Z/IPL display entry information" ++ziplDisplayTest zipl.2 info/z2.1 --info=1 + + testing="GRUB fallback directive" + grubTest grub.5 fallback/g5.1 --remove-kernel=/boot/vmlinuz-2.4.7-ac3 \ +diff --git a/test/results/info/z2.1 b/test/results/info/z2.1 +new file mode 100644 +index 0000000..e5ce3a1 +--- /dev/null ++++ b/test/results/info/z2.1 +@@ -0,0 +1,6 @@ ++index=1 ++kernel=/boot/vmlinuz-3.10.0-514.6.2.el7.s390x ++args="crashkernel=auto rd.dasd=0.0.0120 rd.dasd=0.0.0121 rd.dasd=0.0.0122 rd.dasd=0.0.0123 rd.lvm.lv=rhel_ibm-z-68/root rd.lvm.lv=rhel_ibm-z-68/swap rd.znet=qeth,0.0.8000,0.0.8001,0.0.8002,layer2=1,portname=z-68,portno=0 LANG=en_US.UTF-8 systemd.log_level=debug systemd.log_target=kmsg" ++root=/dev/mapper/rhel_ibm--z--68-root ++initrd=/boot/initramfs-3.10.0-514.6.2.el7.s390x.img ++title=3.10.0-514.6.2.el7.s390x_with_debugging +diff --git a/test/zipl.2 b/test/zipl.2 +new file mode 100644 +index 0000000..f064b2a +--- /dev/null ++++ b/test/zipl.2 +@@ -0,0 +1,22 @@ ++[defaultboot] ++defaultauto ++prompt=1 ++timeout=5 ++default=3.10.0-514.6.2.el7.s390x_with_debugging ++target=/boot ++[3.10.0-514.6.2.el7.s390x] ++ image=/boot/vmlinuz-3.10.0-514.6.2.el7.s390x ++ parameters="root=/dev/mapper/rhel_ibm--z--68-root crashkernel=auto rd.dasd=0.0.0120 rd.dasd=0.0.0121 rd.dasd=0.0.0122 rd.dasd=0.0.0123 rd.lvm.lv=rhel_ibm-z-68/root rd.lvm.lv=rhel_ibm-z-68/swap rd.znet=qeth,0.0.8000,0.0.8001,0.0.8002,layer2=1,portname=z-68,portno=0 LANG=en_US.UTF-8" ++ ramdisk=/boot/initramfs-3.10.0-514.6.2.el7.s390x.img ++[3.10.0-514.6.2.el7.s390x_with_debugging] ++ image=/boot/vmlinuz-3.10.0-514.6.2.el7.s390x ++ parameters="root=/dev/mapper/rhel_ibm--z--68-root crashkernel=auto rd.dasd=0.0.0120 rd.dasd=0.0.0121 rd.dasd=0.0.0122 rd.dasd=0.0.0123 rd.lvm.lv=rhel_ibm-z-68/root rd.lvm.lv=rhel_ibm-z-68/swap rd.znet=qeth,0.0.8000,0.0.8001,0.0.8002,layer2=1,portname=z-68,portno=0 LANG=en_US.UTF-8 systemd.log_level=debug systemd.log_target=kmsg" ++ ramdisk=/boot/initramfs-3.10.0-514.6.2.el7.s390x.img ++[linux] ++ image=/boot/vmlinuz-3.10.0-514.el7.s390x ++ ramdisk=/boot/initramfs-3.10.0-514.el7.s390x.img ++ parameters="root=/dev/mapper/rhel_ibm--z--68-root crashkernel=auto rd.dasd=0.0.0120 rd.dasd=0.0.0121 rd.dasd=0.0.0122 rd.dasd=0.0.0123 rd.lvm.lv=rhel_ibm-z-68/root rd.lvm.lv=rhel_ibm-z-68/swap rd.znet=qeth,0.0.8000,0.0.8001,0.0.8002,layer2=1,portname=z-68,portno=0 LANG=en_US.UTF-8" ++[linux-0-rescue-196fd0394b7442a6838686745f03fd04] ++ image=/boot/vmlinuz-0-rescue-196fd0394b7442a6838686745f03fd04 ++ ramdisk=/boot/initramfs-0-rescue-196fd0394b7442a6838686745f03fd04.img ++ parameters="root=/dev/mapper/rhel_ibm--z--68-root crashkernel=auto rd.dasd=0.0.0120 rd.dasd=0.0.0121 rd.dasd=0.0.0122 rd.dasd=0.0.0123 rd.lvm.lv=rhel_ibm-z-68/root rd.lvm.lv=rhel_ibm-z-68/swap rd.znet=qeth,0.0.8000,0.0.8001,0.0.8002,layer2=1,portname=z-68,portno=0" +-- +2.9.3 + diff --git a/SOURCES/0073-Fix-info-for-s390x-s390-1285601.patch b/SOURCES/0073-Fix-info-for-s390x-s390-1285601.patch new file mode 100644 index 0000000..aa14b71 --- /dev/null +++ b/SOURCES/0073-Fix-info-for-s390x-s390-1285601.patch @@ -0,0 +1,59 @@ +From dab391a5c52622b4c08f87dc394f133419da218a Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Tue, 14 Mar 2017 15:20:53 -0400 +Subject: [PATCH 73/75] Fix --info for s390x/s390 (#1285601) + +The --info flag for grubby on s390/s390x always returned (null). Fixed +codepath to use extractTitle where necessary and get the actual title. + +Related: rhbz#1285601 +--- + grubby.c | 15 +++++++++++---- + 1 file changed, 11 insertions(+), 4 deletions(-) + +diff --git a/grubby.c b/grubby.c +index 4d3834b..f960ebd 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -2782,7 +2782,7 @@ void setFallbackImage(struct grubConfig *config, int hasNew) + } + } + +-void displayEntry(struct singleEntry *entry, const char *prefix, int index) ++void displayEntry(struct grubConfig *config, struct singleEntry *entry, const char *prefix, int index) + { + struct singleLine *line; + char *root = NULL; +@@ -2877,7 +2877,14 @@ void displayEntry(struct singleEntry *entry, const char *prefix, int index) + + line = getLineByType(LT_TITLE, entry->lines); + if (line) { +- printf("title=%s\n", line->elements[1].item); ++ char *entryTitle; ++ /* if we can extractTitle, then it's a zipl config and ++ * if not then we go ahead with what's existed prior */ ++ entryTitle = extractTitle(config, line); ++ if (!entryTitle) { ++ entryTitle=line->elements[1].item; ++ } ++ printf("title=%s\n", entryTitle); + } else { + char *title; + line = getLineByType(LT_MENUENTRY, entry->lines); +@@ -3277,11 +3284,11 @@ int displayInfo(struct grubConfig *config, char *kernel, const char *prefix) + printf("lba\n"); + } + +- displayEntry(entry, prefix, i); ++ displayEntry(config, entry, prefix, i); + + i++; + while ((entry = findEntryByPath(config, kernel, prefix, &i))) { +- displayEntry(entry, prefix, i); ++ displayEntry(config, entry, prefix, i); + i++; + } + +-- +2.9.3 + diff --git a/SOURCES/0074-Add-s390-s390x-set-default-index-test-1285601.patch b/SOURCES/0074-Add-s390-s390x-set-default-index-test-1285601.patch new file mode 100644 index 0000000..08022cf --- /dev/null +++ b/SOURCES/0074-Add-s390-s390x-set-default-index-test-1285601.patch @@ -0,0 +1,59 @@ +From 34a70a8041862757b951fb25fa060386c9c7db0e Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Tue, 14 Mar 2017 22:39:20 -0400 +Subject: [PATCH 74/75] Add s390/s390x set-default-index test (#1285601) + +Adds a test to ensure set-default-index actually works for s390 and +s390x platforms. + +Related: rhbz#1285601 +--- + test.sh | 2 ++ + test/results/default/z2.1 | 22 ++++++++++++++++++++++ + 2 files changed, 24 insertions(+) + create mode 100644 test/results/default/z2.1 + +diff --git a/test.sh b/test.sh +index 34ba4d7..7225c9f 100755 +--- a/test.sh ++++ b/test.sh +@@ -314,6 +314,8 @@ liloDisplayTest lilo.1 defaultkernel/l1.1 --default-kernel + testing="Z/IPL default directive" + ziplTest zipl.1 default/z1.1 --add-kernel /boot/new-kernel --title test + ziplTest zipl.1 default/z1.2 --add-kernel /boot/new-kernel --title test --make-default ++testing="Z/IPL default index directive" ++ziplTest zipl.2 default/z2.1 --set-default-index=0 + testing="Z/IPL display default index" + ziplDisplayTest zipl.1 defaultindex/0 --default-index + testing="Z/IPL display default title" +diff --git a/test/results/default/z2.1 b/test/results/default/z2.1 +new file mode 100644 +index 0000000..93e7491 +--- /dev/null ++++ b/test/results/default/z2.1 +@@ -0,0 +1,22 @@ ++[defaultboot] ++defaultauto ++prompt=1 ++timeout=5 ++default=3.10.0-514.6.2.el7.s390x ++target=/boot ++[3.10.0-514.6.2.el7.s390x] ++ image=/boot/vmlinuz-3.10.0-514.6.2.el7.s390x ++ parameters="root=/dev/mapper/rhel_ibm--z--68-root crashkernel=auto rd.dasd=0.0.0120 rd.dasd=0.0.0121 rd.dasd=0.0.0122 rd.dasd=0.0.0123 rd.lvm.lv=rhel_ibm-z-68/root rd.lvm.lv=rhel_ibm-z-68/swap rd.znet=qeth,0.0.8000,0.0.8001,0.0.8002,layer2=1,portname=z-68,portno=0 LANG=en_US.UTF-8" ++ ramdisk=/boot/initramfs-3.10.0-514.6.2.el7.s390x.img ++[3.10.0-514.6.2.el7.s390x_with_debugging] ++ image=/boot/vmlinuz-3.10.0-514.6.2.el7.s390x ++ parameters="root=/dev/mapper/rhel_ibm--z--68-root crashkernel=auto rd.dasd=0.0.0120 rd.dasd=0.0.0121 rd.dasd=0.0.0122 rd.dasd=0.0.0123 rd.lvm.lv=rhel_ibm-z-68/root rd.lvm.lv=rhel_ibm-z-68/swap rd.znet=qeth,0.0.8000,0.0.8001,0.0.8002,layer2=1,portname=z-68,portno=0 LANG=en_US.UTF-8 systemd.log_level=debug systemd.log_target=kmsg" ++ ramdisk=/boot/initramfs-3.10.0-514.6.2.el7.s390x.img ++[linux] ++ image=/boot/vmlinuz-3.10.0-514.el7.s390x ++ ramdisk=/boot/initramfs-3.10.0-514.el7.s390x.img ++ parameters="root=/dev/mapper/rhel_ibm--z--68-root crashkernel=auto rd.dasd=0.0.0120 rd.dasd=0.0.0121 rd.dasd=0.0.0122 rd.dasd=0.0.0123 rd.lvm.lv=rhel_ibm-z-68/root rd.lvm.lv=rhel_ibm-z-68/swap rd.znet=qeth,0.0.8000,0.0.8001,0.0.8002,layer2=1,portname=z-68,portno=0 LANG=en_US.UTF-8" ++[linux-0-rescue-196fd0394b7442a6838686745f03fd04] ++ image=/boot/vmlinuz-0-rescue-196fd0394b7442a6838686745f03fd04 ++ ramdisk=/boot/initramfs-0-rescue-196fd0394b7442a6838686745f03fd04.img ++ parameters="root=/dev/mapper/rhel_ibm--z--68-root crashkernel=auto rd.dasd=0.0.0120 rd.dasd=0.0.0121 rd.dasd=0.0.0122 rd.dasd=0.0.0123 rd.lvm.lv=rhel_ibm-z-68/root rd.lvm.lv=rhel_ibm-z-68/swap rd.znet=qeth,0.0.8000,0.0.8001,0.0.8002,layer2=1,portname=z-68,portno=0" +-- +2.9.3 + diff --git a/SOURCES/0075-Fix-setDefaultImage-for-s390-s390x-1285601.patch b/SOURCES/0075-Fix-setDefaultImage-for-s390-s390x-1285601.patch new file mode 100644 index 0000000..fe8c8cf --- /dev/null +++ b/SOURCES/0075-Fix-setDefaultImage-for-s390-s390x-1285601.patch @@ -0,0 +1,32 @@ +From 6a55388a609d0c9f237a651a356df77d165b3e83 Mon Sep 17 00:00:00 2001 +From: Robert Marshall +Date: Tue, 14 Mar 2017 22:25:02 -0400 +Subject: [PATCH 75/75] Fix setDefaultImage for s390/s390x (#1285601) + +The setDefaultImage routine has never actually supported s390/s390x when +picking an arbitrary index because a zipl config never has the property +defaultIsIndex set to 1. Eliminating the extraneous check resolved the +issue on s390/s390x and does not appear to break other platforms. + +Related: rhbz#1285601 +--- + grubby.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/grubby.c b/grubby.c +index f960ebd..7219d64 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -2633,8 +2633,7 @@ void setDefaultImage(struct grubConfig *config, int isAddingBootEntry, + } + + /* Case 2: user picked an arbitrary index as the default boot entry */ +- if (newDefaultBootEntryIndex >= FIRST_ENTRY_INDEX +- && config->cfi->defaultIsIndex) { ++ if (newDefaultBootEntryIndex >= FIRST_ENTRY_INDEX) { + indexToVerify = newDefaultBootEntryIndex; + + /* user chose to make latest boot entry the default */ +-- +2.9.3 + diff --git a/SOURCES/prune_debug b/SOURCES/prune_debug new file mode 100755 index 0000000..7aa086b --- /dev/null +++ b/SOURCES/prune_debug @@ -0,0 +1,173 @@ +#!/bin/sh + +###################################################################### +# Prune undesired systemd.debug entries in kernels that are not +# marked for debugging. See Red Hat bugzilla 1285601. +###################################################################### + +PATH=/usr/bin:/usr/sbin +EPOCH_DATE=$(date +"%s") +LOG_DIR="/var/log" +LOG_FILE="${LOG_DIR}/grubby_prune_debug" + +display_event() +{ + EVENT_LABEL="$1" + EVENT_DATA="$2" + JUSTIFIED_LABEL=$(printf "%-12s" "${EVENT_LABEL}") + LOG_TIMESTAMP=$(date +"%s") + echo "[${LOG_TIMESTAMP}] ${JUSTIFIED_LABEL}: ${EVENT_DATA}" >> "${LOG_FILE}" +} + +exit_event() +{ + display_event "Exit" "Exiting script" + exit $1 +} + +find_entry_by_title() +{ + SEARCH_TITLE=$1 + + display_event "Examine" "Searching for entry title - ${SEARCH_TITLE}" + + for current_index in $(grubby --info=ALL|grep "^index="| sed 's/^index=//') ; do + CURRENT_TITLE=$(grubby --info="${current_index}" 2> /dev/null |grep "^title=" | sed 's/^title=//') + + # do not do anything if this was empty + [ -z "${CURRENT_TITLE}" ] && continue + + if [ "${CURRENT_TITLE}" = "${SEARCH_TITLE}" ]; then + echo "${current_index}" + break; + fi + done +} + +[ -d "${LOG_DIR}" ] || mkdir -p -m 0755 "${LOG_DIR}" + +display_event "Start" "Begin search for extraneous debug arguments" + +if [ "$(id -u)" -ne 0 ]; then + display_event "Error" "This script may only run as root." + exit_event 0 +fi + +###################################################################### +# Back up the grub.cfg for sanity +###################################################################### +BOOTLOADER_CFG= +BOOTLOADER_CFG_BK= + +if [ -f "/etc/grub2.cfg" ]; then + BOOTLOADER_CFG=$(realpath "/etc/grub2.cfg") + BOOTLOADER_CFG_BK="${BOOTLOADER_CFG}.${EPOCH_DATE}.rpmsave" +elif [ -f "/etc/grub2-efi.cfg" ]; then + BOOTLOADER_CFG=$(realpath "/etc/grub2-efi.cfg") + BOOTLOADER_CFG_BK="${BOOTLOADER_CFG}.${EPOCH_DATE}.rpmsave" +elif [ -f "/etc/zipl.conf" ]; then + BOOTLOADER_CFG=$(realpath "/etc/zipl.conf") + BOOTLOADER_CFG_BK="${BOOTLOADER_CFG}.${EPOCH_DATE}.rpmsave" +elif [ -f "/etc/yaboot.conf" ]; then + BOOTLOADER_CFG=$(realpath "/etc/yaboot.conf") + BOOTLOADER_CFG_BK="${BOOTLOADER_CFG}.${EPOCH_DATE}.rpmsave" +fi + +if [ -z "${BOOTLOADER_CFG}" ]; then + display_event "Error" "Could not find a bootloader configuration to back up" + exit_event 0 +fi + +if [ -f "${BOOTLOADER_CFG}" ]; then + if cp -a "${BOOTLOADER_CFG}" "${BOOTLOADER_CFG_BK}" 2> /dev/null; then + display_event "Copied" \ + "Current configuration backed up to ${BOOTLOADER_CFG_BK}" + else + display_event "Error" "Could not write ${BOOTLOADER_CFG_BK}" + exit_event 0 + fi +fi + +###################################################################### +# Figure out what the debugging tag will look like +###################################################################### +ARCH=$(uname -m) +if [ $ARCH = 's390' -o $ARCH = 's390x' ]; then + DEBUGGING_TAG="_with_debugging" +else + DEBUGGING_TAG=" with debugging" +fi + +###################################################################### +# Remove the systemd.debug kernel arguments from standard non-debug +# kernel entries only +###################################################################### +display_event "Examine" "Searching for distribution provided debugging entries" +for entry_index in $(grubby --info=ALL|grep "^index="| sed 's/^index=//') ; do + INDEX_TITLE=$(grubby --info="${entry_index}" 2> /dev/null |grep "^title=" | sed 's/^title=//') + + # do not do anything if this was empty + [ -z "${INDEX_TITLE}" ] && continue + + if echo "${INDEX_TITLE}" | grep -q "${DEBUGGING_TAG}$"; then + display_event "Found" "Found distribution provided debugging entry - ${INDEX_TITLE}" + NON_DEBUG_TITLE=$(echo "${INDEX_TITLE}" | sed "s/${DEBUGGING_TAG}$//") + NON_DEBUG_INDEX=$(find_entry_by_title "${NON_DEBUG_TITLE}") + + if [ -n "${NON_DEBUG_INDEX}" ]; then + display_event "Found" "Found matching non-debugging entry - ${NON_DEBUG_TITLE}" + KERNEL_ARGS=$(grubby --info="${NON_DEBUG_INDEX}" 2> /dev/null |grep "^args=") + if echo "${KERNEL_ARGS}" | grep -E -q 'systemd.debug|systemd.log_level=debug|systemd.log_target=kmsg'; then + if grubby --update-kernel="${NON_DEBUG_INDEX}" --remove-args="systemd.debug systemd.log_level=debug systemd.log_target=kmsg"; then + display_event "Update" "Removed debugging arguments for ${NON_DEBUG_TITLE}" + else + display_event "Error" "grubby failed to remove debug argument from ${NON_DEBUG_TITLE}" + fi + else + display_event "Skip" "No debugging arguments to remove for ${NON_DEBUG_TITLE}" + fi + else + display_event "Error" "Could not find the matching non-debugging entry - ${NON_DEBUG_TITLE}" + fi + fi +done + +###################################################################### +# The default entry should not have debugging statements +###################################################################### + +# source of ALLOW_DEBUGGING_DEFAULT +[ -f /etc/sysconfig/kernel ] && . /etc/sysconfig/kernel + +CURRENT_DEFAULT_INDEX=$(grubby --default-index) +CURRENT_TITLE=$(grubby --info="${CURRENT_DEFAULT_INDEX}" 2> /dev/null |grep "^title=" | sed 's/^title=//') +if echo "${CURRENT_TITLE}" | grep -q "${DEBUGGING_TAG}$"; then + case "${ALLOW_DEBUGGING_DEFAULT}" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) + display_event "Examine" "Detected user preference to allow debugging default entries if present" + exit_event 0 + ;; + esac + + display_event "Examine" "Search for entry without debugging to replace default entry - ${CURRENT_TITLE}" + + unset NON_DEBUG_INDEX + unset NON_DEBUG_TITLE + + ARCH=$(uname -m) + NON_DEBUG_TITLE=$(echo "${CURRENT_TITLE}" | sed "s/${DEBUGGING_TAG}$//") + + NON_DEBUG_INDEX=$(find_entry_by_title "${NON_DEBUG_TITLE}") + + if [ -n "${NON_DEBUG_INDEX}" ]; then + if grubby --set-default-index="${NON_DEBUG_INDEX}"; then + display_event "Update" "Selected ${NON_DEBUG_TITLE} as the new default entry" + else + display_event "Error" "Could not set ${NON_DEBUG_TITLE} as default" + fi + else + display_event "Error" "Could not find the matching non-debugging entry" + fi +fi + +exit_event 0 diff --git a/SPECS/grubby.spec b/SPECS/grubby.spec index 15955ee..0a5ff0c 100644 --- a/SPECS/grubby.spec +++ b/SPECS/grubby.spec @@ -1,11 +1,12 @@ Name: grubby Version: 8.28 -Release: 18%{?dist} +Release: 21%{?dist} Summary: Command line tool for updating bootloader configs Group: System Environment/Base License: GPLv2+ URL: http://git.fedorahosted.org/git/grubby.git Source0: https://git.fedorahosted.org/cgit/grubby.git/snapshot/%{name}-%{version}-1.tar.bz2 +Source1: prune_debug Patch0001: 0001-Only-set-RPM_OPT_FLAGS-if-undefined.patch Patch0002: 0002-If-we-re-using-multiboot-add-a-new-mbmodule-not-an-i.patch Patch0003: 0003-Use-PREFIX-during-make-install.patch @@ -66,6 +67,21 @@ Patch0057: 0057-Update-grubby-man-page-contents-bz1232168.patch Patch0058: 0058-Fix-inline-help-typo-1232168.patch Patch0059: 0059-More-edits-for-grubby.8-1232168.patch Patch0060: 0060-Minor-man-page-changes-1232168.patch +Patch0061: 0061-Rename-setDefaultImage-variables.patch +Patch0062: 0062-Add-index-constant-definitions-instead-of-open-coded.patch +Patch0063: 0063-Track-configuration-modifications.patch +Patch0064: 0064-Fix-some-test-cases-where-the-resulting-default-inde.patch +Patch0065: 0065-Don-t-assume-make-default-just-because-set-index-was.patch +Patch0066: 0066-Clarify-set-default-index-in-the-man-page.patch +Patch0067: 0067-Add-multi-entry-removal-test-1285601.patch +Patch0068: 0068-Fix-findTemplate-index-logic-1285601.patch +Patch0069: 0069-Write-correct-default-to-environment-1285601.patch +Patch0070: 0070-Initialize-variable-for-ppc-environment-1285601.patch +Patch0071: 0071-Fix-initial-saved_entry-read-issue-1285601.patch +Patch0072: 0072-Add-s390-s390x-info-test-1285601.patch +Patch0073: 0073-Fix-info-for-s390x-s390-1285601.patch +Patch0074: 0074-Add-s390-s390x-set-default-index-test-1285601.patch +Patch0075: 0075-Fix-setDefaultImage-for-s390-s390x-1285601.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: pkgconfig glib2-devel popt-devel @@ -111,6 +127,8 @@ make test %install rm -rf $RPM_BUILD_ROOT make install DESTDIR=$RPM_BUILD_ROOT PREFIX=%{_prefix} mandir=%{_mandir} +install -d -m 0755 $RPM_BUILD_ROOT/usr/libexec/grubby/ +install -m 0755 %{SOURCE1} $RPM_BUILD_ROOT/usr/libexec/grubby/ %ifarch %{arm} mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ install -p uboot $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/uboot @@ -122,6 +140,8 @@ echo " " >> $RPM_BUILD_ROOT/boot/boot.scr %clean rm -rf $RPM_BUILD_ROOT +%post +/usr/libexec/grubby/prune_debug %files %defattr(-,root,root,-) @@ -130,6 +150,7 @@ rm -rf $RPM_BUILD_ROOT %{_prefix}/sbin/new-kernel-pkg %{_prefix}/sbin/grubby %{_mandir}/man8/*.8* +/usr/libexec/grubby/prune_debug %ghost %config(noreplace) %{_sysconfdir}/sysconfig/kernel %ifarch %{arm} %config(noreplace) %{_sysconfdir}/sysconfig/uboot @@ -137,6 +158,23 @@ rm -rf $RPM_BUILD_ROOT %endif %changelog +* Tue Mar 14 2017 rmarshall@redhat.com - 8.28-21 +- Fixes --info flag on s390/s390x. + Related: rhbz#1420749 +- Fixes --set-default-index on s390/s390x. + Related: rhbz#1420749 +- Allows prune_debug to run on s390/s390x. + Resolves: rhbz#1420749 + +* Mon Mar 06 2017 rmarshall@redhat.com - 8.28-20 +- Resolve coverity scan issues in the prune_debug shell script. + Resolves: rhbz#1420749 + +* Mon Mar 06 2017 rmarshall@redhat.com - 8.28-19 +- Fixed an issue where grubby's logic set the wrong default + boot entry. + Resolves: #1420749 + * Fri Jul 01 2016 rmarshall@redhat.com - 8.28-18 - Patched new-kernel-pkg so that kernel installations when MAKEDEBUG is set would put the debugging entries after the non-debugging entries.