From: Yu Watanabe Date: Mon, 30 Jun 2025 06:18:47 +0000 (+0900) Subject: chase: allow to request O_PATH fd even with CHASE_NONEXISTENT X-Git-Tag: v258-rc1~101^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=628f45f4a35937b64833309709e840b63c84f56b;p=thirdparty%2Fsystemd.git chase: allow to request O_PATH fd even with CHASE_NONEXISTENT --- 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))