From 1133dea477b461a4ceaa8f9ceb58f536edccd8ec Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 20 Feb 2018 12:46:14 +0100 Subject: [PATCH] xattr-util: support AT_EMPTY_PATH in fgetxattrat_fake() Let's expose fstatat() like behaviour if AT_EMPTY_PATH is defined. Also, check the specified flags returning EINVAL on the flags we don't emulate. --- src/basic/xattr-util.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index 12d04eeffb..6f568ff074 100644 --- a/src/basic/xattr-util.c +++ b/src/basic/xattr-util.c @@ -31,6 +31,7 @@ #include "macro.h" #include "sparse-endian.h" #include "stdio-util.h" +#include "string-util.h" #include "time-util.h" #include "xattr-util.h" @@ -111,11 +112,21 @@ ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, /* The kernel doesn't have a fgetxattrat() command, hence let's emulate one */ - fd = openat(dirfd, filename, O_CLOEXEC|O_PATH|(flags & AT_SYMLINK_NOFOLLOW ? O_NOFOLLOW : 0)); - if (fd < 0) - return -errno; + if (flags & ~(AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH)) + return -EINVAL; - xsprintf(fn, "/proc/self/fd/%i", fd); + if (isempty(filename)) { + if (!(flags & AT_EMPTY_PATH)) + return -EINVAL; + + xsprintf(fn, "/proc/self/fd/%i", dirfd); + } else { + fd = openat(dirfd, filename, O_CLOEXEC|O_PATH|(flags & AT_SYMLINK_NOFOLLOW ? O_NOFOLLOW : 0)); + if (fd < 0) + return -errno; + + xsprintf(fn, "/proc/self/fd/%i", fd); + } l = getxattr(fn, attribute, value, size); if (l < 0)