]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: make path_is_root_at() not fail even when /proc is mounted
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 21 Jul 2023 16:23:17 +0000 (01:23 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 21 Jul 2023 17:20:27 +0000 (02:20 +0900)
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

index d9ef7ec9326dd0bd49f73e6eeaeb17e045386a4d..1c67e785aa3fb535fc64e07714a5acf5e4955e7c 100644 (file)
@@ -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;