diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-09-21 17:38:17 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-09-22 08:13:34 +0200 |
commit | 660087dc9c4a5c610da99e7b6b1772e371eb0a80 (patch) | |
tree | 30c430acb6cb10d05837c89b533ade607116bfb3 /src/mount | |
parent | core/dbus-path: use structured initialization in one more place (diff) | |
download | systemd-660087dc9c4a5c610da99e7b6b1772e371eb0a80.tar.xz systemd-660087dc9c4a5c610da99e7b6b1772e371eb0a80.zip |
tree-wide: add path_simplify_alloc() and use it
path_simplify_full()/path_simplify() are changed to allow a NULL path, for
which a NULL is returned. Generally, callers have already asserted before that
the argument is nonnull. This way path_simplify_full()/path_simplify() and
path_simplify_alloc() behave consistently.
In sd-device.c, logging in device_set_syspath() is intentionally dropped: other
branches don't log.
In mount-tool.c, logging in parse_argv() is changed to log the user-specified
value, not the simplified string. In an error message, we should show the
actual argument we got, not some transformed version.
Diffstat (limited to 'src/mount')
-rw-r--r-- | src/mount/mount-tool.c | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index a0dcdf53b6..90feb2f197 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -83,30 +83,26 @@ STATIC_DESTRUCTOR_REGISTER(arg_property, strv_freep); STATIC_DESTRUCTOR_REGISTER(arg_automount_property, strv_freep); static int parse_where(const char *input, char **ret_where) { - _cleanup_free_ char *where = NULL; int r; assert(input); assert(ret_where); if (arg_transport == BUS_TRANSPORT_LOCAL) { - r = chase(input, NULL, CHASE_NONEXISTENT, &where, NULL); + r = chase(input, NULL, CHASE_NONEXISTENT, ret_where, NULL); if (r < 0) return log_error_errno(r, "Failed to make path %s absolute: %m", input); } else { - where = strdup(input); - if (!where) - return log_oom(); - - path_simplify(where); - - if (!path_is_absolute(where)) + if (!path_is_absolute(input)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Path must be absolute when operating remotely: %s", - where); + input); + + r = path_simplify_alloc(input, ret_where); + if (r < 0) + return log_error_errno(r, "Failed to simplify path %s: %m", input); } - *ret_where = TAKE_PTR(where); return 0; } @@ -441,17 +437,16 @@ static int parse_argv(int argc, char *argv[]) { r = chase(u, NULL, 0, &arg_mount_what, NULL); if (r < 0) return log_error_errno(r, "Failed to make path %s absolute: %m", u); - } else { - arg_mount_what = strdup(argv[optind]); - if (!arg_mount_what) - return log_oom(); - path_simplify(arg_mount_what); - - if (!path_is_absolute(arg_mount_what)) + } else { + if (!path_is_absolute(argv[optind])) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Path must be absolute when operating remotely: %s", - arg_mount_what); + argv[optind]); + + r = path_simplify_alloc(argv[optind], &arg_mount_what); + if (r < 0) + return log_error_errno(r, "Failed to simplify path: %m"); } } @@ -1054,11 +1049,9 @@ static int action_umount( for (int i = optind; i < argc; i++) { _cleanup_free_ char *p = NULL; - p = strdup(argv[i]); - if (!p) - return log_oom(); - - path_simplify(p); + r = path_simplify_alloc(argv[i], &p); + if (r < 0) + return r; r = stop_mounts(bus, p); if (r < 0) |