tree-wide: use path_join() instead of prefix_roota() in various cases

prefix_roota() is something we should stop using. It is bad for three
reasons:

1. As it names suggests it's supposed to be used when working relative
   to some root directory, but given it doesn't follow symlinks (and
   instead just stupidly joins paths) it is not a good choice for that.

2. More often than not it is currently used with inputs under control of
   the user, and that is icky given it typically allocates memory on the
   stack.

3. It's a redundant interface, where chase_symlinks() and path_join()
   already exist as better, safer interfaces.

Hence, let's start moving things from prefix_roota() to path_join() for
the cases where that's appropriate.
This commit is contained in:
Lennart Poettering
2022-08-22 19:15:29 +01:00
committed by Luca Boccassi
parent 8ef6106de4
commit 8e7e4a730b
8 changed files with 92 additions and 44 deletions
+8 -2
View File
@@ -2295,6 +2295,7 @@ static int unit_attach_pid_to_cgroup_via_bus(Unit *u, pid_t pid, const char *suf
}
int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
_cleanup_free_ char *joined = NULL;
CGroupMask delegated_mask;
const char *p;
void *pidp;
@@ -2320,8 +2321,13 @@ int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
if (isempty(suffix_path))
p = u->cgroup_path;
else
p = prefix_roota(u->cgroup_path, suffix_path);
else {
joined = path_join(u->cgroup_path, suffix_path);
if (!joined)
return -ENOMEM;
p = joined;
}
delegated_mask = unit_get_delegate_mask(u);