X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fcgroup-util.c;h=9692a07f56484a2071321fb9371e66cca79543be;hb=6d2357247b198314d972932415d65a42f83a9b6e;hp=e6ceb99454b8460408c64f9797b0ed884e04624c;hpb=6e8314c420eb375847c9e526745c2caec802399d;p=elogind.git diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index e6ceb9945..9692a07f5 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) {