The virFileResolveLink utility function relied on the POSIX guarantee
that stat.st_size of a symlink is the length of the value. However,
on some types of file systems, it is invalid, so do not rely on it.
Use gnulib's areadlink module instead.
* bootstrap (modules): Add areadlink.
* src/util/util.c: Include "areadlink.h".
Let areadlink perform the readlink and malloc.
* configure.in (AC_CHECK_FUNCS): Remove readlink. No need,
since it's presence is guaranteed by gnulib.
<$gnulib_tool || exit
modules='
+areadlink
base64
c-ctype
close
AC_SYS_LARGEFILE
dnl Availability of various common functions (non-fatal if missing).
-AC_CHECK_FUNCS([cfmakeraw regexec uname sched_getaffinity getuid getgid posix_fallocate mmap readlink])
+AC_CHECK_FUNCS([cfmakeraw regexec uname sched_getaffinity getuid getgid posix_fallocate mmap])
dnl Availability of various not common threadsafe functions
AC_CHECK_FUNCS([strerror_r strtok_r getmntent_r getgrnam_r getpwuid_r])
#include <mntent.h>
#endif
+#include "areadlink.h"
#include "virterror_internal.h"
#include "logging.h"
#include "event.h"
int virFileResolveLink(const char *linkpath,
char **resultpath)
{
-#ifdef HAVE_READLINK
struct stat st;
- char *buf;
- int n;
*resultpath = NULL;
return 0;
}
- /* Posix says that 'st_size' field from
- * result of an lstat() call is filled with
- * number of bytes in the destination
- * filename.
- */
- if (VIR_ALLOC_N(buf, st.st_size + 1) < 0)
- return -ENOMEM;
-
- if ((n = readlink(linkpath, buf, st.st_size)) < 0) {
- VIR_FREE(buf);
- return -errno;
- }
-
- buf[n] = '\0';
+ *resultpath = areadlink (linkpath);
- *resultpath = buf;
- return 0;
-#else
- if (!(*resultpath = strdup(linkpath)))
- return -ENOMEM;
- return 0;
-#endif
+ return *resultpath == NULL ? -1 : 0;
}
/*