]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountpoint-util: use get_proc_field()
authorMike Yuan <me@yhndnzj.com>
Thu, 13 Mar 2025 15:09:55 +0000 (16:09 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 May 2025 04:10:26 +0000 (13:10 +0900)
src/basic/mountpoint-util.c

index 6fc5e52a8e411171c6d1a6811a5446cce4819910..23653160a0fd6ec87bdc520b53458589988199be 100644 (file)
@@ -141,7 +141,6 @@ int name_to_handle_at_try_fid(
 
 static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *ret_mnt_id) {
         char path[STRLEN("/proc/self/fdinfo/") + DECIMAL_STR_MAX(int)];
-        _cleanup_free_ char *fdinfo = NULL;
         _cleanup_close_ int subfd = -EBADF;
         int r;
 
@@ -158,19 +157,13 @@ static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *ret_mn
                 xsprintf(path, "/proc/self/fdinfo/%i", subfd);
         }
 
-        r = read_full_virtual_file(path, &fdinfo, NULL);
+        _cleanup_free_ char *p = NULL;
+        r = get_proc_field(path, "mnt_id", &p);
         if (r == -ENOENT)
-                return proc_fd_enoent_errno();
+                return -EBADF;
         if (r < 0)
                 return r;
 
-        char *p = find_line_startswith(fdinfo, "mnt_id:");
-        if (!p)
-                return -EBADMSG;
-
-        p = skip_leading_chars(p, /* bad = */ NULL);
-        p[strcspn(p, WHITESPACE)] = 0;
-
         return safe_atoi(p, ret_mnt_id);
 }