From: Lennart Poettering Date: Tue, 20 Feb 2018 11:46:14 +0000 (+0100) Subject: xattr-util: support AT_EMPTY_PATH in fgetxattrat_fake() X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=4c5943104751a678b7ad886131806dd964618d2f;p=elogind.git 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. --- diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index 1a309be2e..97387579d 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" @@ -112,11 +113,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; + + if (isempty(filename)) { + if (!(flags & AT_EMPTY_PATH)) + return -EINVAL; - xsprintf(fn, "/proc/self/fd/%i", fd); + 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)