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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2023-09-22 08:13:34 +02:00
parent 7902df1263
commit 660087dc9c
13 changed files with 84 additions and 124 deletions
+2 -14
View File
@@ -589,7 +589,6 @@ int getgroups_alloc(gid_t** gids) {
int get_home_dir(char **ret) {
struct passwd *p;
const char *e;
char *h;
uid_t u;
assert(ret);
@@ -622,18 +621,12 @@ int get_home_dir(char **ret) {
return -EINVAL;
found:
h = strdup(e);
if (!h)
return -ENOMEM;
*ret = path_simplify(h);
return 0;
return path_simplify_alloc(e, ret);
}
int get_shell(char **ret) {
struct passwd *p;
const char *e;
char *s;
uid_t u;
assert(ret);
@@ -665,12 +658,7 @@ int get_shell(char **ret) {
return -EINVAL;
found:
s = strdup(e);
if (!s)
return -ENOMEM;
*ret = path_simplify(s);
return 0;
return path_simplify_alloc(e, ret);
}
int reset_uid_gid(void) {