summaryrefslogtreecommitdiff
path: root/src/basic/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-10-02 11:43:19 +0200
committerLennart Poettering <lennart@poettering.net>2015-10-02 11:44:05 +0200
commitdf241a67c0d5311dd15e227162d7e886541da16c (patch)
treecd26371b0353e493039e9cac32c002fe17d865ad /src/basic/util.c
parente46831f0f1e2ef0a6cd333b639af1327745ccb5b (diff)
util: rework fgetxattrat_fake() to use O_PATH
That way, we don't ever open the file, thus leave the atime untouched, and this works even when unprivileged.
Diffstat (limited to 'src/basic/util.c')
-rw-r--r--src/basic/util.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/basic/util.c b/src/basic/util.c
index c63ec0ceb0..9f520462cf 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -6168,16 +6168,19 @@ int openpt_in_namespace(pid_t pid, int flags) {
}
ssize_t fgetxattrat_fake(int dirfd, const char *filename, const char *attribute, void *value, size_t size, int flags) {
+ char fn[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(int) + 1];
_cleanup_close_ int fd = -1;
ssize_t l;
/* The kernel doesn't have a fgetxattrat() command, hence let's emulate one */
- fd = openat(dirfd, filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOATIME|(flags & AT_SYMLINK_NOFOLLOW ? O_NOFOLLOW : 0));
+ fd = openat(dirfd, filename, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_PATH|(flags & AT_SYMLINK_NOFOLLOW ? O_NOFOLLOW : 0));
if (fd < 0)
return -errno;
- l = fgetxattr(fd, attribute, value, size);
+ xsprintf(fn, "/proc/self/fd/%i", fd);
+
+ l = getxattr(fn, attribute, value, size);
if (l < 0)
return -errno;