From 0783d8da50bd1efc6cc57d95d4fc2dfbc7a7bc00 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 22 Jan 2025 11:54:50 +0100 Subject: [PATCH 1/2] xattr-util: use at_flags_normalize_nofollow() at one more place --- src/basic/xattr-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index d2daf87ec91..896d85bf5cc 100644 --- a/src/basic/xattr-util.c +++ b/src/basic/xattr-util.c @@ -175,7 +175,7 @@ int fd_getcrtime_at( * most sense. */ if (statx(fd, strempty(path), - (flags & ~AT_SYMLINK_FOLLOW)|(FLAGS_SET(flags, AT_SYMLINK_FOLLOW) ? 0 : AT_SYMLINK_NOFOLLOW)|AT_STATX_DONT_SYNC, + at_flags_normalize_nofollow(flags)|AT_STATX_DONT_SYNC, STATX_BTIME, &sx) >= 0 && (sx.stx_mask & STATX_BTIME) && From 4b11087b37efeb5843997bc69fb319e71faa830d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 22 Jan 2025 11:54:34 +0100 Subject: [PATCH 2/2] fs-util: also add an at_flags_normalize_follow() helper This is the reverse of at_flags_normalize_follow() --- src/basic/fs-util.h | 9 +++++++++ src/basic/stat-util.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/basic/fs-util.h b/src/basic/fs-util.h index eb031a0ccde..b2c01079901 100644 --- a/src/basic/fs-util.h +++ b/src/basic/fs-util.h @@ -172,3 +172,12 @@ static inline int at_flags_normalize_nofollow(int flags) { flags |= AT_SYMLINK_NOFOLLOW; return flags; } + +static inline int at_flags_normalize_follow(int flags) { + if (FLAGS_SET(flags, AT_SYMLINK_NOFOLLOW)) { + assert(!FLAGS_SET(flags, AT_SYMLINK_FOLLOW)); + flags &= ~AT_SYMLINK_NOFOLLOW; + } else + flags |= AT_SYMLINK_FOLLOW; + return flags; +} diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 2181ee2df51..10bd7c0fe17 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -298,7 +298,7 @@ int inode_same_at(int fda, const char *filea, int fdb, const char *fileb, int fl flags |= AT_EMPTY_PATH; } - int ntha_flags = (flags & AT_EMPTY_PATH) | (FLAGS_SET(flags, AT_SYMLINK_NOFOLLOW) ? 0 : AT_SYMLINK_FOLLOW); + int ntha_flags = at_flags_normalize_follow(flags) & (AT_EMPTY_PATH|AT_SYMLINK_FOLLOW); _cleanup_free_ struct file_handle *ha = NULL, *hb = NULL; int mntida = -1, mntidb = -1;