加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0055-Make-editenv-chase-symlinks-including-those-across-d.patch 2.83 KB
一键复制 编辑 原始数据 按行查看 历史
geliwei 提交于 2022-04-13 15:15 . update to grub2-2.02-120.el8.src.rpm
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 3 Sep 2014 10:38:00 -0400
Subject: [PATCH] Make editenv chase symlinks including those across devices.
This lets us make /boot/grub2/grubenv a symlink to
/boot/efi/EFI/fedora/grubenv even though they're different mount points,
which allows /usr/bin/grub2-editenv to be the same across platforms
(i.e. UEFI vs BIOS).
Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
---
Makefile.util.def | 9 +++++++++
util/editenv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 53 insertions(+), 2 deletions(-)
diff --git a/Makefile.util.def b/Makefile.util.def
index c7b775bce..d08713b55 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -231,8 +231,17 @@ program = {
common = util/grub-editenv.c;
common = util/editenv.c;
+ common = util/grub-install-common.c;
common = grub-core/osdep/init.c;
+ common = grub-core/osdep/compress.c;
+ extra_dist = grub-core/osdep/unix/compress.c;
+ extra_dist = grub-core/osdep/basic/compress.c;
+ common = util/mkimage.c;
+ common = grub-core/osdep/config.c;
+ common = util/config.c;
+ common = util/resolve.c;
+ ldadd = '$(LIBLZMA)';
ldadd = libgrubmods.a;
ldadd = libgrubgcry.a;
ldadd = libgrubkern.a;
diff --git a/util/editenv.c b/util/editenv.c
index c6f8d2298..d8d1dad6a 100644
--- a/util/editenv.c
+++ b/util/editenv.c
@@ -37,6 +37,7 @@ grub_util_create_envblk_file (const char *name)
FILE *fp;
char *buf;
char *namenew;
+ char *rename_target = xstrdup(name);
buf = xmalloc (DEFAULT_ENVBLK_SIZE);
@@ -59,7 +60,48 @@ grub_util_create_envblk_file (const char *name)
free (buf);
fclose (fp);
- if (grub_util_rename (namenew, name) < 0)
- grub_util_error (_("cannot rename the file %s to %s"), namenew, name);
+ ssize_t size = 1;
+ while (1)
+ {
+ char *linkbuf;
+ ssize_t retsize;
+
+ linkbuf = xmalloc(size+1);
+ retsize = grub_util_readlink (rename_target, linkbuf, size);
+ if (retsize < 0 && (errno == ENOENT || errno == EINVAL))
+ {
+ free (linkbuf);
+ break;
+ }
+ else if (retsize < 0)
+ {
+ grub_util_error (_("cannot rename the file %s to %s: %m"), namenew, name);
+ free (linkbuf);
+ free (namenew);
+ return;
+ }
+ else if (retsize == size)
+ {
+ free(linkbuf);
+ size += 128;
+ continue;
+ }
+
+ free (rename_target);
+ linkbuf[retsize] = '\0';
+ rename_target = linkbuf;
+ }
+
+ int rc = grub_util_rename (namenew, rename_target);
+ if (rc < 0 && errno == EXDEV)
+ {
+ rc = grub_install_copy_file (namenew, rename_target, 1);
+ grub_util_unlink (namenew);
+ }
+
+ if (rc < 0)
+ grub_util_error (_("cannot rename the file %s to %s: %m"), namenew, name);
+
free (namenew);
+ free (rename_target);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化