]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
chase: allow to request O_PATH fd even with CHASE_NONEXISTENT
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 30 Jun 2025 06:18:47 +0000 (15:18 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 11 Jul 2025 01:39:55 +0000 (10:39 +0900)
src/basic/chase.c

index fe060324ef56c41419278e71bd04aef8a0415524..3a929498bf2cc1a1a832497bad244d162efd3f32 100644 (file)
@@ -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))