From bd96111d5fa8d3c05aad6aed21243d6b0534055d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 22 Jul 2023 01:23:17 +0900 Subject: [PATCH] fd-util: make path_is_root_at() not fail even when /proc is mounted path_get_mnt_id_at() -> fd_fdinfo_mnt_id() may return -EOPNOTSUPP when /proc is mounted, and -ENOSYS otherwise, when an old kernel is used. --- src/basic/fd-util.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index d9ef7ec9326..1c67e785aa3 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -929,17 +929,18 @@ int path_is_root_at(int dir_fd, const char *path) { * $ mount --bind /tmp/x /tmp/x/y * * Note, statx() does not provide the mount ID and path_get_mnt_id_at() does not work when an old - * kernel is used without /proc mounted. In that case, let's assume that we do not have such spurious - * mount points in an early boot stage, and silently skip the following check. */ + * kernel is used. In that case, let's assume that we do not have such spurious mount points in an + * early boot stage, and silently skip the following check. */ if (!FLAGS_SET(st.nsx.stx_mask, STATX_MNT_ID)) { int mntid; r = path_get_mnt_id_at(dir_fd, "", &mntid); - if (r == -ENOSYS) - return true; /* skip the mount ID check */ - if (r < 0) + if (r < 0) { + if (ERRNO_IS_NOT_SUPPORTED(r)) + return true; /* skip the mount ID check */ return r; + } assert(mntid >= 0); st.nsx.stx_mnt_id = mntid; @@ -950,10 +951,11 @@ int path_is_root_at(int dir_fd, const char *path) { int mntid; r = path_get_mnt_id_at(dir_fd, "..", &mntid); - if (r == -ENOSYS) - return true; /* skip the mount ID check */ - if (r < 0) + if (r < 0) { + if (ERRNO_IS_NOT_SUPPORTED(r)) + return true; /* skip the mount ID check */ return r; + } assert(mntid >= 0); pst.nsx.stx_mnt_id = mntid; -- 2.47.3