Allow editenv to follow symlinks to find/make grubenv
cover Allow editenv to follow symlinks to find/make grubenv
Hi,
This is a patch series to allow grub-editenv and related utilities to follow symbolic links when finding its config file. This allows, for example, the ability to have two builds of grub for different platforms that have different prefixes set, but still use the same userland grub utilities.
For example, in our EFI builds we'll typically have prefix set as /EFI/fedora (on the EFI System Partition), but when you install on a BIOS machine it'll be /boot/grub2 (which may or may not be its own mountpoint.)
With this patch, on EFI machines we can make /boot/grub2/grubenv a symlink to /boot/efi/EFI/fedora/grubenv , and the same copy of grub-set-default will work on both kinds of systems.
Note: I'm not entirely sure I've done the gnulib parts of the first patch
the preferred way, but they do appear to be functional. I wound up using
"gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname readlink regex" and then only adding in the parts directly related to readlink().
PATCH 2/2 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).
--- Makefile.util.def | 9 +++++++++ util/editenv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-)
Makefile.util.def +9 -0
@@ -228,8 +228,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;
util/editenv.c +44 -2
57 lines not on this page · raw message
Signature · 1 line
1.9.3
PATCH 1/2 Add grub_util_readlink()
In reply to Peter JonesAdd grub_util_readlink(). This requires pulling in stat and readlink from gnulib, which pulls in stat and related headers, but after that the implementation is straightforward.
--- grub-core/gnulib/Makefile.am | 177 +++++++- grub-core/gnulib/gettimeofday.c | 154 +++++++ grub-core/gnulib/pathmax.h | 83 ++++ grub-core/gnulib/readlink.c | 74 ++++ grub-core/gnulib/stat.c | 138 +++++++ grub-core/gnulib/sys_stat.in.h | 732 ++++++++++++++++++++++++++++++++++ grub-core/gnulib/sys_time.in.h | 213 ++++++++++ grub-core/gnulib/sys_types.in.h | 2 + grub-core/gnulib/time.h | 586 +++++++++++++++++++++++++++ grub-core/gnulib/time.in.h | 274 +++++++++++++ grub-core/osdep/windows/hostdisk.c | 6 + include/grub/osdep/hostfile_aros.h | 6 + include/grub/osdep/hostfile_unix.h | 6 + include/grub/osdep/hostfile_windows.h | 2 + m4/gettimeofday.m4 | 138 +++++++ m4/gnulib-cache.m4 | 3 +- m4/gnulib-comp.m4 | 49 +++ m4/largefile.m4 | 146 +++++++ m4/pathmax.m4 | 42 ++ m4/readlink.m4 | 71 ++++ m4/stat.m4 | 71 ++++ m4/sys_stat_h.m4 | 96 +++++ m4/sys_time_h.m4 | 110 +++++ m4/time_h.m4 | 118 ++++++ 24 files changed, 3295 insertions(+), 2 deletions(-) create mode 100644 grub-core/gnulib/gettimeofday.c create mode 100644 grub-core/gnulib/pathmax.h create mode 100644 grub-core/gnulib/readlink.c create mode 100644 grub-core/gnulib/stat.c create mode 100644 grub-core/gnulib/sys_stat.in.h create mode 100644 grub-core/gnulib/sys_time.in.h create mode 100644 grub-core/gnulib/time.h create mode 100644 grub-core/gnulib/time.in.h create mode 100644 m4/gettimeofday.m4 create mode 100644 m4/largefile.m4 create mode 100644 m4/pathmax.m4 create mode 100644 m4/readlink.m4 create mode 100644 m4/stat.m4 create mode 100644 m4/sys_stat_h.m4 create mode 100644 m4/sys_time_h.m4 create mode 100644 m4/time_h.m4
grub-core/gnulib/Makefile.am +176 -1
@@ -21,7 +21,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname regex +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname readlink regex AUTOMAKE_OPTIONS = 1.5 gnits subdir-objects
@@ -326,6 +326,15 @@ libgnu_a_SOURCES += gettext.h ## end gnulib module gettext-h +## begin gnulib module gettimeofday + + +EXTRA_DIST += gettimeofday.c + +EXTRA_libgnu_a_SOURCES += gettimeofday.c + +## end gnulib module gettimeofday + ## begin gnulib module havelib
@@ -596,6 +605,13 @@ EXTRA_libgnu_a_SOURCES += nl_langinfo.c ## end gnulib module nl_langinfo +## begin gnulib module pathmax + + +EXTRA_DIST += pathmax.h + +## end gnulib module pathmax + ## begin gnulib module progname libgnu_a_SOURCES += progname.h progname.c
@@ -611,6 +627,15 @@ EXTRA_libgnu_a_SOURCES += rawmemchr.c ## end gnulib module rawmemchr +## begin gnulib module readlink + + +EXTRA_DIST += readlink.c + +EXTRA_libgnu_a_SOURCES += readlink.c + +## end gnulib module readlink + ## begin gnulib module realloc-posix
@@ -725,6 +750,15 @@ EXTRA_DIST += $(top_srcdir)/build-aux/snippet/warn-on-use.h ## end gnulib module snippet/warn-on-use +## begin gnulib module stat + + +EXTRA_DIST += stat.c + +EXTRA_libgnu_a_SOURCES += stat.c + +## end gnulib module stat + ## begin gnulib module stdalign BUILT_SOURCES += $(STDALIGN_H)
@@ -1280,6 +1314,102 @@ libgnu_a_SOURCES += strnlen1.h strnlen1.c ## end gnulib module strnlen1 +## begin gnulib module sys_stat + +BUILT_SOURCES += sys/stat.h + +# We need the following in order to create <sys/stat.h> when the system +# has one that is incomplete. +sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_at)$(MKDIR_P) sys + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \ + -e 's|@''WINDOWS_64_BIT_ST_SIZE''@|$(WINDOWS_64_BIT_ST_SIZE)|g' \ + -e 's/@''GNULIB_FCHMODAT''@/$(GNULIB_FCHMODAT)/g' \ + -e 's/@''GNULIB_FSTAT''@/$(GNULIB_FSTAT)/g' \ + -e 's/@''GNULIB_FSTATAT''@/$(GNULIB_FSTATAT)/g' \ + -e 's/@''GNULIB_FUTIMENS''@/$(GNULIB_FUTIMENS)/g' \ + -e 's/@''GNULIB_LCHMOD''@/$(GNULIB_LCHMOD)/g' \ + -e 's/@''GNULIB_LSTAT''@/$(GNULIB_LSTAT)/g' \ + -e 's/@''GNULIB_MKDIRAT''@/$(GNULIB_MKDIRAT)/g' \ + -e 's/@''GNULIB_MKFIFO''@/$(GNULIB_MKFIFO)/g' \ + -e 's/@''GNULIB_MKFIFOAT''@/$(GNULIB_MKFIFOAT)/g' \ + -e 's/@''GNULIB_MKNOD''@/$(GNULIB_MKNOD)/g' \ + -e 's/@''GNULIB_MKNODAT''@/$(GNULIB_MKNODAT)/g' \ + -e 's/@''GNULIB_STAT''@/$(GNULIB_STAT)/g' \ + -e 's/@''GNULIB_UTIMENSAT''@/$(GNULIB_UTIMENSAT)/g' \ + -e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \ + -e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \ + -e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \ + -e 's|@''HAVE_LCHMOD''@|$(HAVE_LCHMOD)|g' \ + -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \ + -e 's|@''HAVE_MKDIRAT''@|$(HAVE_MKDIRAT)|g' \ + -e 's|@''HAVE_MKFIFO''@|$(HAVE_MKFIFO)|g' \ + -e 's|@''HAVE_MKFIFOAT''@|$(HAVE_MKFIFOAT)|g' \ + -e 's|@''HAVE_MKNOD''@|$(HAVE_MKNOD)|g' \ + -e 's|@''HAVE_MKNODAT''@|$(HAVE_MKNODAT)|g' \ + -e 's|@''HAVE_UTIMENSAT''@|$(HAVE_UTIMENSAT)|g' \ + -e 's|@''REPLACE_FSTAT''@|$(REPLACE_FSTAT)|g' \ + -e 's|@''REPLACE_FSTATAT''@|$(REPLACE_FSTATAT)|g' \ + -e 's|@''REPLACE_FUTIMENS''@|$(REPLACE_FUTIMENS)|g' \ + -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \ + -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \ + -e 's|@''REPLACE_MKFIFO''@|$(REPLACE_MKFIFO)|g' \ + -e 's|@''REPLACE_MKNOD''@|$(REPLACE_MKNOD)|g' \ + -e 's|@''REPLACE_STAT''@|$(REPLACE_STAT)|g' \ + -e 's|@''REPLACE_UTIMENSAT''@|$(REPLACE_UTIMENSAT)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/sys_stat.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += sys/stat.h sys/stat.h-t +MOSTLYCLEANDIRS += sys + +EXTRA_DIST += sys_stat.in.h + +## end gnulib module sys_stat + +## begin gnulib module sys_time + +BUILT_SOURCES += sys/time.h + +# We need the following in order to create <sys/time.h> when the system +# doesn't have one that works with the given compiler. +sys/time.h: sys_time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_at)$(MKDIR_P) sys + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's/@''HAVE_SYS_TIME_H''@/$(HAVE_SYS_TIME_H)/g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_SYS_TIME_H''@|$(NEXT_SYS_TIME_H)|g' \ + -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \ + -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \ + -e 's/@''HAVE_GETTIMEOFDAY''@/$(HAVE_GETTIMEOFDAY)/g' \ + -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \ + -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \ + -e 's/@''REPLACE_STRUCT_TIMEVAL''@/$(REPLACE_STRUCT_TIMEVAL)/g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/sys_time.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += sys/time.h sys/time.h-t + +EXTRA_DIST += sys_time.in.h + +## end gnulib module sys_time + ## begin gnulib module sys_types BUILT_SOURCES += sys/types.h
@@ -1334,6 +1464,51 @@ EXTRA_DIST += sysexits.in.h ## end gnulib module sysexits +## begin gnulib module time + +BUILT_SOURCES += time.h + +# We need the following in order to create <time.h> when the system +# doesn't have one that works with the given compiler. +time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@''GUARD_PREFIX''@|GL|g' \ + -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ + -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ + -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ + -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ + -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \ + -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \ + -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \ + -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \ + -e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \ + -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \ + -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \ + -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \ + -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \ + -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \ + -e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \ + -e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \ + -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ + -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ + -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ + -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ + -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \ + -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ + -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ + < $(srcdir)/time.in.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += time.h time.h-t + +EXTRA_DIST += time.in.h + +## end gnulib module time + ## begin gnulib module unistd BUILT_SOURCES += unistd.h
grub-core/gnulib/gettimeofday.c new file +154 -0
154 lines not on this page · raw message
grub-core/gnulib/pathmax.h new file +83 -0
83 lines not on this page · raw message
grub-core/gnulib/readlink.c new file +74 -0
74 lines not on this page · raw message
grub-core/gnulib/stat.c new file +138 -0
138 lines not on this page · raw message
grub-core/gnulib/sys_stat.in.h new file +732 -0
732 lines not on this page · raw message
grub-core/gnulib/sys_time.in.h new file +213 -0
213 lines not on this page · raw message
grub-core/gnulib/sys_types.in.h +2 -0
@@ -23,7 +23,9 @@ #ifndef _@GUARD_PREFIX@_SYS_TYPES_H/* The include_next requires a split double-inclusion guard. */ +# define _GL_INCLUDING_SYS_TYPES_H #@INCLUDE_NEXT@ @NEXT_SYS_TYPES_H@ +# undef _GL_INCLUDING_SYS_TYPES_H #ifndef _@GUARD_PREFIX@_SYS_TYPES_H#define _@GUARD_PREFIX@_SYS_TYPES_H
grub-core/gnulib/time.h new file +586 -0
586 lines not on this page · raw message
grub-core/gnulib/time.in.h new file +274 -0
274 lines not on this page · raw message
grub-core/osdep/windows/hostdisk.c +6 -0
@@ -353,6 +353,12 @@ grub_util_mkdir (const char *dir)free (windows_name); } +ssize_t +grub_util_readlink (const char *name,char *buf,size_t bufsize) +{ +return readlink (name, buf, bufsize); +} +int grub_util_rename (const char *from,const char *to) {
include/grub/osdep/hostfile_aros.h +6 -0
@@ -68,6 +68,12 @@ grub_util_rename (const char *from, const char *to)return rename (from, to); } +static inline ssize_t +grub_util_readlink (const char *name,char *buf,size_t bufsize) +{ +return readlink (name, buf, bufsize); +} +#define grub_util_mkdir (a) mkdir ((a), 0755)struct grub_util_fd
include/grub/osdep/hostfile_unix.h +6 -0
@@ -71,6 +71,12 @@ grub_util_rename (const char *from, const char *to)return rename (from, to); } +static inline ssize_t +grub_util_readlink (const char *name,char *buf,size_t bufsize) +{ +return readlink (name, buf, bufsize); +} +#define grub_util_mkdir (a) mkdir ((a), 0755)#if defined (__NetBSD__)
include/grub/osdep/hostfile_windows.h +2 -0
@@ -41,6 +41,8 @@ typedef struct grub_util_fd_dir *grub_util_fd_dir_t;int grub_util_rename (const char *from,const char *to); +ssize_t +grub_util_readlink (const char *name,char *buf,size_t bufsize);int grub_util_unlink (const char *name);void
m4/gettimeofday.m4 new file +138 -0
138 lines not on this page · raw message
m4/gnulib-cache.m4 +2 -1
@@ -27,7 +27,7 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname regex +# gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname readlink regex # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([])
@@ -39,6 +39,7 @@ gl_MODULES([ getline gettext progname + readlink regex ]) gl_AVOID([])
m4/gnulib-comp.m4 +49 -0
184 lines not on this page · raw message
m4/largefile.m4 new file +146 -0
137 lines not on this page · raw message
m4/pathmax.m4 new file +42 -0
42 lines not on this page · raw message
m4/readlink.m4 new file +71 -0
71 lines not on this page · raw message
m4/stat.m4 new file +71 -0
71 lines not on this page · raw message
m4/sys_stat_h.m4 new file +96 -0
96 lines not on this page · raw message
m4/sys_time_h.m4 new file +110 -0
110 lines not on this page · raw message
m4/time_h.m4 new file +118 -0
118 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.9.3
Part of the diff is not shown here. View the raw message.
В Thu, 4 Sep 2014 11:36:53 -0400
Peter Jones <[email protected]> пишет:
Quoted 11 lines
Hi,
This is a patch series to allow grub-editenv and related utilities to follow symbolic links when finding its config file. This allows, for example, the ability to have two builds of grub for different platforms that have different prefixes set, but still use the same userland grub utilities.For example, in our EFI builds we'll typically have prefix set as /EFI/fedora (on the EFI System Partition), but when you install on a BIOS machine it'll be
/boot/grub2(which may or may not be its own mountpoint.)
This sounds more like misusing of ${prefix}. ${prefix} is supposed to be target independent. Any target-dependent file is going into ${prefix}/${grub_cpu}-${grub_platform}. That allows to use the same /boot/grub for any platform (and possibly make run-time platform-specific decision).
Quoted 14 lines
With this patch, on EFI machines we can make
/boot/grub2/grubenva symlink to/boot/efi/EFI/fedora/grubenv, and the same copy of grub-set-default will work on both kinds of systems.Note: I'm not entirely sure I've done the gnulib parts of the first patch
the preferred way, but they do appear to be functional. I wound up using
"gnulib-tool --import --dir=. --lib=libgnu --source-base=grub-core/gnulib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files argp error fnmatch getdelim getline gettext progname readlink regex" and then only adding in the parts directly related toreadlink()._______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 2/2] Make editenv chase symlinks including those across devices.
In reply to Peter JonesQuoted 50 lines · Peter Jones
This lets us make
/boot/grub2/grubenva symlink to/boot/efi/EFI/fedora/grubenveven though they're different mount points, which allows/usr/bin/grub2-editenvto be the same across platforms (i.e. UEFI vs BIOS).Signed-off-by Peter Jones <[email protected]>Reviewed-by Adam Jackson <[email protected]>--- Makefile.util.def | 9 +++++++++ util/editenv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-)Makefile.util.def +9
-0@@ -228,8 +228,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;util/editenv.c +1
-0@@ -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);
util/editenv.c grub_util_create_envblk_file (const char *name) · line 70
Quoted 10 lines
util/editenv.c +8
-2-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 I get this code correctly you essentially canonicalize the link manually. Why not use already available canonicalization functions?
Quoted 38 lines
util/editenv.c +35
-0+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); }