From: Yu Watanabe Date: Fri, 21 Jul 2023 16:23:17 +0000 (+0900) Subject: fd-util: make path_is_root_at() not fail even when /proc is mounted X-Git-Tag: v254-rc3~7^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bd96111d5fa8d3c05aad6aed21243d6b0534055d;p=thirdparty%2Fsystemd.git 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. --- 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;