]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
grub-editenv: Add grub_util_readlink()
authorPeter Jones <pjones@redhat.com>
Fri, 17 Jan 2020 16:10:42 +0000 (17:10 +0100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 18 Feb 2020 14:14:13 +0000 (15:14 +0100)
Currently grub-editenv and related tools are not able to follow symbolic
links when finding their config file. For example the grub-editenv create
command will wrongly overwrite a symlink in /boot/grub2/grubenv with a new
regular file, instead of creating a file in the path the symlink points to.

A following patch will change that and add support in grub-editenv to
follow symbolic links when finding the grub environment variables file.

Add a grub_util_readlink() helper function that is just a wrapper around
the platform specific function to read the value of a symbolic link. This
helper function will be used by the following patch for grub-editenv.

The helper function is not added for Windows, since this operating system
doesn't have a primitive to read the contents of a symbolic link.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
include/grub/osdep/hostfile_aros.h
include/grub/osdep/hostfile_unix.h

index a059c0fa40a5eccbf594497f763687e5bc010740..161fbb7bdfd65ac52a4566f768691bccca22d0f9 100644 (file)
@@ -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
index 9ffe46fa3ca50f68e3dd4853d09cf555523bc14a..17cd3aa8b304ce7a729c43ffcebdf31449c5f2a2 100644 (file)
@@ -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__)