From 628f45f4a35937b64833309709e840b63c84f56b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 30 Jun 2025 15:18:47 +0900 Subject: [PATCH] chase: allow to request O_PATH fd even with CHASE_NONEXISTENT --- src/basic/chase.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/basic/chase.c b/src/basic/chase.c index fe060324ef5..3a929498bf2 100644 --- a/src/basic/chase.c +++ b/src/basic/chase.c @@ -126,10 +126,6 @@ int chaseat(int dir_fd, const char *path, ChaseFlags flags, char **ret_path, int assert(!FLAGS_SET(flags, CHASE_STEP|CHASE_EXTRACT_FILENAME)); assert(dir_fd >= 0 || dir_fd == AT_FDCWD); - /* Either the file may be missing, or we return an fd to the final object, but both make no sense */ - if (FLAGS_SET(flags, CHASE_NONEXISTENT)) - assert(!ret_fd); - if (FLAGS_SET(flags, CHASE_STEP)) assert(!ret_fd); @@ -552,11 +548,13 @@ int chaseat(int dir_fd, const char *path, ChaseFlags flags, char **ret_path, int } if (ret_fd) { - /* Return the O_PATH fd we currently are looking to the caller. It can translate it to a - * proper fd by opening /proc/self/fd/xyz. */ - - assert(fd >= 0); - *ret_fd = TAKE_FD(fd); + if (exists) { + /* Return the O_PATH fd we currently are looking to the caller. It can translate it + * to a proper fd by opening /proc/self/fd/xyz. */ + assert(fd >= 0); + *ret_fd = TAKE_FD(fd); + } else + *ret_fd = -EBADF; } if (FLAGS_SET(flags, CHASE_STEP)) -- 2.47.3