]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount-tool: accept fstab-style identifiers for remote what too
authorMike Yuan <me@yhndnzj.com>
Fri, 14 Feb 2025 22:41:58 +0000 (23:41 +0100)
committerMike Yuan <me@yhndnzj.com>
Mon, 3 Mar 2025 09:45:56 +0000 (10:45 +0100)
fstab-style identifiers have stable translation to absolute paths
in the file system, hence it makes no sense to reject them
even for remote mounts.

src/mount/mount-tool.c

index df3394bb2c397229690a5abc1cb91b575f44e064..aa6fd27b03c39c8c7c40aa16cd8c33c8b20e62fa 100644 (file)
@@ -464,27 +464,31 @@ static int parse_argv(int argc, char *argv[]) {
                                 arg_mount_what = strdup(argv[optind]);
                                 if (!arg_mount_what)
                                         return log_oom();
-
-                        } else if (arg_transport == BUS_TRANSPORT_LOCAL && arg_canonicalize) {
-                                _cleanup_free_ char *u = NULL;
-
-                                u = fstab_node_to_udev_node(argv[optind]);
-                                if (!u)
-                                        return log_oom();
-
-                                r = chase(u, /* root= */ NULL, /* flags= */ 0, &arg_mount_what, /* ret_fd= */ NULL);
-                                if (r < 0)
-                                        return log_error_errno(r, "Failed to make path %s absolute: %m", u);
-
                         } else {
-                                if (!path_is_absolute(argv[optind]))
-                                        return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
-                                                               "Path must be absolute when operating remotely or when canonicalization is turned off: %s",
-                                                               argv[optind]);
-
-                                r = path_simplify_alloc(argv[optind], &arg_mount_what);
-                                if (r < 0)
-                                        return log_error_errno(r, "Failed to simplify path: %m");
+                                _cleanup_free_ char *u = NULL;
+                                const char *p = argv[optind];
+
+                                if (arg_canonicalize) {
+                                        u = fstab_node_to_udev_node(p);
+                                        if (!u)
+                                                return log_oom();
+                                        p = u;
+                                }
+
+                                if (arg_transport == BUS_TRANSPORT_LOCAL && arg_canonicalize) {
+                                        r = chase(p, /* root= */ NULL, /* flags= */ 0, &arg_mount_what, /* ret_fd= */ NULL);
+                                        if (r < 0)
+                                                return log_error_errno(r, "Failed to chase path '%s': %m", p);
+                                } else {
+                                        if (!path_is_absolute(p))
+                                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                                                       "Path must be absolute when operating remotely or when canonicalization is turned off: %s",
+                                                                       p);
+
+                                        r = path_simplify_alloc(p, &arg_mount_what);
+                                        if (r < 0)
+                                                return log_oom();
+                                }
                         }
                 }