cgroup: move controller to dirname translation into join_path_legacy()

Let's simplify things a bit.
This commit is contained in:
Lennart Poettering 2015-09-03 14:56:26 +02:00
parent a1f686daf5
commit 569b19d8fe
1 changed files with 13 additions and 16 deletions

View File

@ -460,20 +460,23 @@ static const char *controller_to_dirname(const char *controller) {
return controller; return controller;
} }
static int join_path_legacy(const char *controller_dn, const char *path, const char *suffix, char **fs) { static int join_path_legacy(const char *controller, const char *path, const char *suffix, char **fs) {
const char *dn;
char *t = NULL; char *t = NULL;
assert(fs); assert(fs);
assert(controller_dn); assert(controller);
dn = controller_to_dirname(controller);
if (isempty(path) && isempty(suffix)) if (isempty(path) && isempty(suffix))
t = strappend("/sys/fs/cgroup/", controller_dn); t = strappend("/sys/fs/cgroup/", dn);
else if (isempty(path)) else if (isempty(path))
t = strjoin("/sys/fs/cgroup/", controller_dn, "/", suffix, NULL); t = strjoin("/sys/fs/cgroup/", dn, "/", suffix, NULL);
else if (isempty(suffix)) else if (isempty(suffix))
t = strjoin("/sys/fs/cgroup/", controller_dn, "/", path, NULL); t = strjoin("/sys/fs/cgroup/", dn, "/", path, NULL);
else else
t = strjoin("/sys/fs/cgroup/", controller_dn, "/", path, "/", suffix, NULL); t = strjoin("/sys/fs/cgroup/", dn, "/", path, "/", suffix, NULL);
if (!t) if (!t)
return -ENOMEM; return -ENOMEM;
@ -509,8 +512,8 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch
if (!controller) { if (!controller) {
char *t; char *t;
/* If no controller is specified, we assume only the /* If no controller is specified, we return the path
* path below the controller matters */ * *below* the controllers, without any prefix. */
if (!path && !suffix) if (!path && !suffix)
return -EINVAL; return -EINVAL;
@ -537,14 +540,8 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch
if (unified > 0) if (unified > 0)
r = join_path_unified(path, suffix, fs); r = join_path_unified(path, suffix, fs);
else { else
const char *dn; r = join_path_legacy(controller, path, suffix, fs);
dn = controller_to_dirname(controller);
r = join_path_legacy(dn, path, suffix, fs);
}
if (r < 0) if (r < 0)
return r; return r;