We will need to traverse the symlinks one step at the time. Therefore we need to see where a symlink is pointing to. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/libvirt_private.syms | 1 + src/util/virfile.c | 12 ++++++++++++ src/util/virfile.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index cfeb43cf0..7f7dcfe44 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1615,6 +1615,7 @@ virFileReadAllQuiet; virFileReadBufQuiet; virFileReadHeaderFD; virFileReadLimFD; +virFileReadLink; virFileRelLinkPointsTo; virFileRemove; virFileRemoveLastComponent; diff --git a/src/util/virfile.c b/src/util/virfile.c index bf8099e34..49ea1d1f0 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -76,6 +76,7 @@ #include "virutil.h" #include "c-ctype.h" +#include "areadlink.h" #define VIR_FROM_THIS VIR_FROM_NONE @@ -1614,6 +1615,17 @@ virFileIsLink(const char *linkpath) return S_ISLNK(st.st_mode) != 0; } +/* + * Read where symlink is pointing to. + * + * Returns 0 on success (@linkpath is a successfully read link), + * -1 with errno set upon error. + */ +int +virFileReadLink(const char *linkpath, char **resultpath) +{ + return (*resultpath = areadlink(linkpath)) ? 0 : -1; +} /* * Finds a requested executable file in the PATH env. e.g.: diff --git a/src/util/virfile.h b/src/util/virfile.h index 0343acd5b..981a9e07d 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -166,6 +166,8 @@ int virFileResolveAllLinks(const char *linkpath, int virFileIsLink(const char *linkpath) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; +int virFileReadLink(const char *linkpath, char **resultpath); + char *virFindFileInPath(const char *file); char *virFileFindResource(const char *filename, -- 2.11.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list