summaryrefslogtreecommitdiffstats
path: root/src/portable
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-09-21 17:38:17 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2023-09-22 08:13:34 +0200
commit660087dc9c4a5c610da99e7b6b1772e371eb0a80 (patch)
tree30c430acb6cb10d05837c89b533ade607116bfb3 /src/portable
parentcore/dbus-path: use structured initialization in one more place (diff)
downloadsystemd-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/portable')
-rw-r--r--src/portable/portable.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/portable/portable.c b/src/portable/portable.c
index 545a3ed5d2..52f38dc83e 100644
--- a/src/portable/portable.c
+++ b/src/portable/portable.c
@@ -838,6 +838,7 @@ static int portable_changes_add(
_cleanup_free_ char *p = NULL, *s = NULL;
PortableChange *c;
+ int r;
assert(path);
assert(!changes == !n_changes);
@@ -855,19 +856,13 @@ static int portable_changes_add(
return -ENOMEM;
*changes = c;
- p = strdup(path);
- if (!p)
- return -ENOMEM;
-
- path_simplify(p);
-
- if (source) {
- s = strdup(source);
- if (!s)
- return -ENOMEM;
+ r = path_simplify_alloc(path, &p);
+ if (r < 0)
+ return r;
- path_simplify(s);
- }
+ r = path_simplify_alloc(source, &s);
+ if (r < 0)
+ return r;
c[(*n_changes)++] = (PortableChange) {
.type_or_errno = type_or_errno,