1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

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.
This commit is contained in:
Yu Watanabe 2023-07-22 01:23:17 +09:00
parent 7487115766
commit bd96111d5f

View File

@ -929,17 +929,18 @@ int path_is_root_at(int dir_fd, const char *path) {
* $ mount --bind /tmp/x /tmp/x/y * $ 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 * 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 * kernel is used. In that case, let's assume that we do not have such spurious mount points in an
* mount points in an early boot stage, and silently skip the following check. */ * early boot stage, and silently skip the following check. */
if (!FLAGS_SET(st.nsx.stx_mask, STATX_MNT_ID)) { if (!FLAGS_SET(st.nsx.stx_mask, STATX_MNT_ID)) {
int mntid; int mntid;
r = path_get_mnt_id_at(dir_fd, "", &mntid); r = path_get_mnt_id_at(dir_fd, "", &mntid);
if (r == -ENOSYS) if (r < 0) {
return true; /* skip the mount ID check */ if (ERRNO_IS_NOT_SUPPORTED(r))
if (r < 0) return true; /* skip the mount ID check */
return r; return r;
}
assert(mntid >= 0); assert(mntid >= 0);
st.nsx.stx_mnt_id = mntid; st.nsx.stx_mnt_id = mntid;
@ -950,10 +951,11 @@ int path_is_root_at(int dir_fd, const char *path) {
int mntid; int mntid;
r = path_get_mnt_id_at(dir_fd, "..", &mntid); r = path_get_mnt_id_at(dir_fd, "..", &mntid);
if (r == -ENOSYS) if (r < 0) {
return true; /* skip the mount ID check */ if (ERRNO_IS_NOT_SUPPORTED(r))
if (r < 0) return true; /* skip the mount ID check */
return r; return r;
}
assert(mntid >= 0); assert(mntid >= 0);
pst.nsx.stx_mnt_id = mntid; pst.nsx.stx_mnt_id = mntid;