summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-02-11 17:15:38 +0100
committerLennart Poettering <lennart@poettering.net>2014-02-11 17:16:08 +0100
commit89f7c8465cd1ab37347dd0c15920bce31e8225df (patch)
tree2db96d4cc6b4ee0e81c420b480b6c177228e38b3 /src/shared
parent2d2ebd6b8f0775b93480bf05464865a0c78a9390 (diff)
machined: optionally, allow registration of pre-existing units (scopes
or services) as machine with machined
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/cgroup-util.c37
1 files changed, 8 insertions, 29 deletions
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index e6ceb99454..9692a07f56 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -1282,39 +1282,18 @@ int cg_pid_get_user_unit(pid_t pid, char **unit) {
}
int cg_path_get_machine_name(const char *path, char **machine) {
- const char *e, *n, *x;
- char *s, *r;
- size_t l;
-
- assert(path);
- assert(machine);
-
- /* Skip slices, if there are any */
- e = skip_slices(path);
-
- n = strchrnul(e, '/');
- if (e == n)
- return -ENOENT;
-
- s = strndupa(e, n - e);
- s = cg_unescape(s);
-
- x = startswith(s, "machine-");
- if (!x)
- return -ENOENT;
- if (!endswith(x, ".scope"))
- return -ENOENT;
+ _cleanup_free_ char *u = NULL, *sl = NULL;
+ int r;
- l = strlen(x);
- if (l <= 6)
- return -ENOENT;
+ r = cg_path_get_unit(path, &u);
+ if (r < 0)
+ return r;
- r = strndup(x, l - 6);
- if (!r)
+ sl = strjoin("/run/systemd/machines/unit:", u, NULL);
+ if (!sl)
return -ENOMEM;
- *machine = r;
- return 0;
+ return readlink_malloc(sl, machine);
}
int cg_pid_get_machine_name(pid_t pid, char **machine) {