From 8fce6645278f907bffd40546071927414357ddc7 Mon Sep 17 00:00:00 2001 From: ZhouPengcheng Date: Wed, 14 Dec 2022 16:16:30 +0800 Subject: [PATCH] fix delete the last kernel menuentry error --- ...lete-the-last-kernel-menuentry-error.patch | 55 +++++++++++++++++++ grubby.spec | 6 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 fix-delete-the-last-kernel-menuentry-error.patch diff --git a/fix-delete-the-last-kernel-menuentry-error.patch b/fix-delete-the-last-kernel-menuentry-error.patch new file mode 100644 index 0000000..a177f21 --- /dev/null +++ b/fix-delete-the-last-kernel-menuentry-error.patch @@ -0,0 +1,55 @@ +From edd876060e6dd1e8fe30a0ec92456d5dde866d3c Mon Sep 17 00:00:00 2001 +From: zhangnan +Date: Mon, 21 Nov 2022 20:53:24 +0800 +Subject: [PATCH] fix grubby delete the last kernel menuentry error + +Grubby now does not distinguish whether the last entry is kernel menuentry, so the last kernel menuentry may be deleted, causing the foolproof mechanism to fail. +This patch add the kernel menuentry identification mechanism to avoid such error. + +diff --git a/grubby.c b/grubby.c +index 4471428..f20b3bd 100644 +--- a/grubby.c ++++ b/grubby.c +@@ -1845,13 +1845,27 @@ static int writeConfig(struct grubConfig * cfg, char * outName, + return rc; + } + +-static int numEntries(struct grubConfig *cfg) { ++static int isKernelEntry(struct singleEntry * entry, struct configFileInfo * cfi) { ++ int findKernel = 0; struct singleLine * line; ++ line = entry->lines; ++ if (isEntryStart(line, cfi)){ ++ while (line && !(line->type == LT_KERNEL || line->type == LT_KERNEL_EFI ++ || line->type == LT_KERNEL_16 || line->type == LT_HYPER || line->type == LT_MBMODULE)){ ++ line = line->next; ++ } ++ if (line) ++ findKernel = 1; ++ } ++ return findKernel; ++} ++ ++static int numKernelEntries(struct grubConfig *cfg, struct configFileInfo * cfi) { + int i = 0; + struct singleEntry * entry; + + entry = cfg->entries; + while (entry) { +- if (!entry->skip) ++ if (!entry->skip && isKernelEntry(entry, cfi)) + i++; + entry = entry->next; + } +@@ -5126,7 +5140,7 @@ int main(int argc, const char ** argv) { + newMBKernel, newMBKernelArgs, newDevTreePath)) return 1; + + +- if (numEntries(config) == 0) { ++ if (numKernelEntries(config, cfi) == 0) { + fprintf(stderr, _("grubby: doing this would leave no kernel entries. " + "Not writing out new config.\n")); + return 1; +-- +2.27.0 + + diff --git a/grubby.spec b/grubby.spec index 1847173..887bdb0 100644 --- a/grubby.spec +++ b/grubby.spec @@ -1,6 +1,6 @@ Name: grubby Version: 8.40 -Release: 29 +Release: 30 Summary: Update and display information about the configuration files License: GPLv2+ URL: https://github.com/rhinstaller/grubby @@ -35,6 +35,7 @@ Patch6017: backport-Fix-maybe-uninitialized-warning.patch Patch9001: fix-make-test-fail-when-no-boot-partition.patch Patch9002: Fix-make-test-fail-for-g2-1.15.patch +Patch9003: fix-delete-the-last-kernel-menuentry-error.patch BuildRequires: gcc pkgconfig glib2-devel popt-devel BuildRequires: libblkid-devel git-core sed make @@ -109,6 +110,9 @@ sed -e "s,@@LIBEXECDIR@@,%{_libexecdir}/installkernel,g" %{SOURCE3} > %{buildroo %{_mandir}/man8/*.8* %changelog +* Wed Dec 14 2022 zhangnan - 8.40-30 +- fix delete the last kernel menuentry error + * Wed Oct 26 2022 yanglongkang - 8.40-29 - rebuild for next release -- Gitee