From: Mike Yuan Date: Mon, 20 Jan 2025 22:02:00 +0000 (+0100) Subject: mountpoint-util: port path_is_mount_point() to chase_and_open_parent() X-Git-Tag: v258-rc1~1536^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6cab0df904089eb1ae7dbf3785fd8a255228eff5;p=thirdparty%2Fsystemd.git mountpoint-util: port path_is_mount_point() to chase_and_open_parent() --- diff --git a/src/basic/mountpoint-util.c b/src/basic/mountpoint-util.c index 6c03d62d2a2..aac8b19430d 100644 --- a/src/basic/mountpoint-util.c +++ b/src/basic/mountpoint-util.c @@ -366,9 +366,8 @@ fallback_fdinfo: /* flags can be AT_SYMLINK_FOLLOW or 0 */ int path_is_mount_point_full(const char *path, const char *root, int flags) { - _cleanup_free_ char *canonical = NULL; - _cleanup_close_ int fd = -EBADF; - int r; + _cleanup_close_ int dfd = -EBADF; + _cleanup_free_ char *fn = NULL; assert(path); assert((flags & ~AT_SYMLINK_FOLLOW) == 0); @@ -379,19 +378,13 @@ int path_is_mount_point_full(const char *path, const char *root, int flags) { /* we need to resolve symlinks manually, we can't just rely on is_mount_point_at() to do that for us; * if we have a structure like /bin -> /usr/bin/ and /usr is a mount point, then the parent that we * look at needs to be /usr, not /. */ - if (FLAGS_SET(flags, AT_SYMLINK_FOLLOW)) { - r = chase(path, root, CHASE_TRAIL_SLASH, &canonical, NULL); - if (r < 0) - return r; - - path = canonical; - } - - fd = open_parent(path, O_PATH|O_CLOEXEC, 0); - if (fd < 0) - return fd; + dfd = chase_and_open_parent(path, root, + CHASE_TRAIL_SLASH|(FLAGS_SET(flags, AT_SYMLINK_FOLLOW) ? 0 : CHASE_NOFOLLOW), + &fn); + if (dfd < 0) + return dfd; - return is_mount_point_at(fd, last_path_component(path), flags); + return is_mount_point_at(dfd, fn, flags); } int path_get_mnt_id_at_fallback(int dir_fd, const char *path, int *ret) {