]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountpoint-util: our baseline includes fdinfo and mnt_id now
authorMike Yuan <me@yhndnzj.com>
Mon, 11 Nov 2024 17:55:10 +0000 (18:55 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 22 Jan 2025 00:12:55 +0000 (01:12 +0100)
src/basic/fd-util.c
src/basic/mountpoint-util.c

index c112f8dbad552f274c5d20e8a17f81a1506b132f..be22d6a04f297176762f73c63cea5fb62bfff45a 100644 (file)
@@ -1113,8 +1113,6 @@ int fds_are_same_mount(int fd1, int fd2) {
                 int mntid;
 
                 r = path_get_mnt_id_at_fallback(fd1, "", &mntid);
-                if (ERRNO_IS_NEG_NOT_SUPPORTED(r))
-                        return true; /* skip the mount ID check */
                 if (r < 0)
                         return r;
                 assert(mntid >= 0);
@@ -1127,8 +1125,6 @@ int fds_are_same_mount(int fd1, int fd2) {
                 int mntid;
 
                 r = path_get_mnt_id_at_fallback(fd2, "", &mntid);
-                if (ERRNO_IS_NEG_NOT_SUPPORTED(r))
-                        return true; /* skip the mount ID check */
                 if (r < 0)
                         return r;
                 assert(mntid >= 0);
index f87e7342de5724318f4e2e8a246e7a312172b82e..b596d32680c4be553ade552aa48838c5b3a5aa0a 100644 (file)
@@ -147,11 +147,10 @@ static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *ret_mn
         char path[STRLEN("/proc/self/fdinfo/") + DECIMAL_STR_MAX(int)];
         _cleanup_free_ char *fdinfo = NULL;
         _cleanup_close_ int subfd = -EBADF;
-        char *p;
         int r;
 
-        assert(ret_mnt_id);
         assert((flags & ~(AT_SYMLINK_FOLLOW|AT_EMPTY_PATH)) == 0);
+        assert(ret_mnt_id);
 
         if ((flags & AT_EMPTY_PATH) && isempty(filename))
                 xsprintf(path, "/proc/self/fdinfo/%i", fd);
@@ -164,16 +163,16 @@ static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *ret_mn
         }
 
         r = read_full_virtual_file(path, &fdinfo, NULL);
-        if (r == -ENOENT) /* The fdinfo directory is a relatively new addition */
-                return proc_mounted() > 0 ? -EOPNOTSUPP : -ENOSYS;
+        if (r == -ENOENT)
+                return proc_fd_enoent_errno();
         if (r < 0)
                 return r;
 
-        p = find_line_startswith(fdinfo, "mnt_id:");
-        if (!p) /* The mnt_id field is a relatively new addition */
-                return -EOPNOTSUPP;
+        char *p = find_line_startswith(fdinfo, "mnt_id:");
+        if (!p)
+                return -EBADMSG;
 
-        p += strspn(p, WHITESPACE);
+        p = skip_leading_chars(p, /* bad = */ NULL);
         p[strcspn(p, WHITESPACE)] = 0;
 
         return safe_atoi(p, ret_mnt_id);