]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: introduce dir_fd_is_root_or_cwd()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 1 Apr 2023 16:25:46 +0000 (01:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 4 Apr 2023 15:52:56 +0000 (00:52 +0900)
src/basic/chase.c
src/basic/fd-util.h
src/shared/find-esp.c

index 7d87f998f1ea109f54a03ccdd573b048742190d0..318454ca88eb81dee3796cd870ea149583b86130 100644 (file)
@@ -162,10 +162,7 @@ int chaseat(int dir_fd, const char *path, ChaseFlags flags, char **ret_path, int
                 /* If we get AT_FDCWD or dir_fd points to "/", then we always resolve symlinks relative to
                  * the host's root. Hence, CHASE_AT_RESOLVE_IN_ROOT is meaningless. */
 
-                if (dir_fd >= 0)
-                        r = dir_fd_is_root(dir_fd);
-                else
-                        r = true;
+                r = dir_fd_is_root_or_cwd(dir_fd);
                 if (r < 0)
                         return r;
                 if (r > 0)
index 91f3d7fe9d4d61804a381bee5c8507b6b2795dec..655ad2928475173d04b138a3ecf42dff1ccc8571 100644 (file)
@@ -2,6 +2,7 @@
 #pragma once
 
 #include <dirent.h>
+#include <fcntl.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <sys/socket.h>
@@ -101,6 +102,9 @@ int read_nr_open(void);
 int fd_get_diskseq(int fd, uint64_t *ret);
 
 int dir_fd_is_root(int dir_fd);
+static inline int dir_fd_is_root_or_cwd(int dir_fd) {
+        return dir_fd == AT_FDCWD ? true : dir_fd_is_root(dir_fd);
+}
 
 /* The maximum length a buffer for a /proc/self/fd/<fd> path needs */
 #define PROC_FD_PATH_MAX \
index 60f80387f8e2cd840fbe4206a1c7ef99aef4b83a..0d45249d6327ce2369b5b77c00235663420fbd97 100644 (file)
@@ -444,10 +444,7 @@ int find_esp_and_warn_at(
 
         assert(rfd >= 0 || rfd == AT_FDCWD);
 
-        if (rfd >= 0)
-                r = dir_fd_is_root(rfd);
-        else
-                r = true;
+        r = dir_fd_is_root_or_cwd(rfd);
         if (r < 0)
                 return log_error_errno(r, "Failed to check if directory file descriptor is root: %m");
         if (r == 0)