2018-07-12 14:56:34 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2014-09-03 17:10:57 +00:00
|
|
|
From: Peter Jones <pjones@redhat.com>
|
|
|
|
Date: Wed, 3 Sep 2014 10:38:00 -0400
|
2018-07-10 19:08:14 +00:00
|
|
|
Subject: [PATCH] Make editenv chase symlinks including those across devices.
|
2014-09-03 17:10:57 +00:00
|
|
|
|
|
|
|
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>
|
|
|
|
---
|
2019-07-16 09:23:51 +00:00
|
|
|
Makefile.util.def | 11 +++++++++++
|
2018-01-17 22:04:09 +00:00
|
|
|
util/editenv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
|
2019-07-16 09:23:51 +00:00
|
|
|
2 files changed, 55 insertions(+), 2 deletions(-)
|
2014-09-03 17:10:57 +00:00
|
|
|
|
|
|
|
diff --git a/Makefile.util.def b/Makefile.util.def
|
2019-08-15 06:01:31 +00:00
|
|
|
index 8717774d510..1f298d05f3d 100644
|
2014-09-03 17:10:57 +00:00
|
|
|
--- a/Makefile.util.def
|
|
|
|
+++ b/Makefile.util.def
|
2019-08-15 06:01:31 +00:00
|
|
|
@@ -240,8 +240,19 @@ program = {
|
2014-09-03 17:10:57 +00:00
|
|
|
|
|
|
|
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;
|
2019-07-16 09:23:51 +00:00
|
|
|
+ common = util/grub-mkimage32.c;
|
|
|
|
+ common = util/grub-mkimage64.c;
|
2014-09-03 17:10:57 +00:00
|
|
|
+ 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
|
2019-08-15 06:01:31 +00:00
|
|
|
index eb2d0c03a98..e61dc1283a4 100644
|
2014-09-03 17:10:57 +00:00
|
|
|
--- a/util/editenv.c
|
|
|
|
+++ b/util/editenv.c
|
2018-01-17 22:04:09 +00:00
|
|
|
@@ -37,6 +37,7 @@ grub_util_create_envblk_file (const char *name)
|
2014-09-03 17:10:57 +00:00
|
|
|
FILE *fp;
|
|
|
|
char *buf;
|
|
|
|
char *namenew;
|
|
|
|
+ char *rename_target = xstrdup(name);
|
|
|
|
|
|
|
|
buf = xmalloc (DEFAULT_ENVBLK_SIZE);
|
|
|
|
|
2019-08-15 06:01:31 +00:00
|
|
|
@@ -60,7 +61,48 @@ grub_util_create_envblk_file (const char *name)
|
2014-09-03 17:10:57 +00:00
|
|
|
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;
|
|
|
|
+ }
|
|
|
|
+
|
2018-01-17 22:04:09 +00:00
|
|
|
+ free (rename_target);
|
2014-09-03 17:10:57 +00:00
|
|
|
+ linkbuf[retsize] = '\0';
|
2018-01-17 22:04:09 +00:00
|
|
|
+ rename_target = linkbuf;
|
2014-09-03 17:10:57 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
}
|