From: Yu Watanabe Date: Sat, 1 Apr 2023 16:25:46 +0000 (+0900) Subject: fd-util: introduce dir_fd_is_root_or_cwd() X-Git-Tag: v254-rc1~806^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e212f422796da9e626030289faf083407c8955df;p=thirdparty%2Fsystemd.git fd-util: introduce dir_fd_is_root_or_cwd() --- diff --git a/src/basic/chase.c b/src/basic/chase.c index 7d87f998f1e..318454ca88e 100644 --- a/src/basic/chase.c +++ b/src/basic/chase.c @@ -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) diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index 91f3d7fe9d4..655ad292847 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -2,6 +2,7 @@ #pragma once #include +#include #include #include #include @@ -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/ path needs */ #define PROC_FD_PATH_MAX \ diff --git a/src/shared/find-esp.c b/src/shared/find-esp.c index 60f80387f8e..0d45249d632 100644 --- a/src/shared/find-esp.c +++ b/src/shared/find-esp.c @@ -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)