加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0040-Fix-initial-saved_entry-read-issue-1285601.patch 2.67 KB
一键复制 编辑 原始数据 按行查看 历史
张彬琛 提交于 2021-01-20 13:34 . import grubby-8.40-38.el8.src.rpm
From a8367596ca63156509eed0b332a077247765b811 Mon Sep 17 00:00:00 2001
From: Robert Marshall <rmarshall@redhat.com>
Date: Tue, 28 Feb 2017 18:31:56 -0500
Subject: [PATCH 40/55] 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 9ccad2735dd..974b81c7864 100644
--- a/grubby.c
+++ b/grubby.c
@@ -2522,6 +2522,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 */
@@ -2587,8 +2590,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, &currentLookupIndex);
+ }
+ /* 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.17.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化