X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fcgroup-util.c;h=43c415d760d67dee78646908affe51cf207fd268;hp=1366f5865f418f7a89fdfcb0de5b1027c098fc97;hb=a0ab566574303be1ca12cdb334f284cfd407caa5;hpb=8af8afd6b3a34d1218826f55ada8ece8b4e36fed diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index 1366f5865..43c415d76 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -1146,17 +1146,22 @@ int cg_get_user_path(char **path) { return 0; } -int cg_get_machine_path(char **path) { - _cleanup_free_ char *root = NULL; +int cg_get_machine_path(const char *machine, char **path) { + _cleanup_free_ char *root = NULL, *escaped = NULL; char *p; assert(path); - if (cg_get_root_path(&root) < 0 || streq(root, "/")) - p = strdup("/machine"); - else - p = strappend(root, "/machine"); + if (machine) { + const char *name = strappenda(machine, ".nspawn"); + + escaped = cg_escape(name); + if (!escaped) + return -ENOMEM; + } + p = strjoin(cg_get_root_path(&root) >= 0 && !streq(root, "/") ? root : "", + "/machine", machine ? "/" : "", machine ? escaped : "", NULL); if (!p) return -ENOMEM; @@ -1306,7 +1311,7 @@ int cg_pid_get_unit(pid_t pid, char **unit) { return cg_path_get_unit(cgroup, unit); } -static const char *skip_label(const char *e) { +_pure_ static const char *skip_label(const char *e) { assert(e); e = strchr(e, '/'); @@ -1522,7 +1527,12 @@ char *cg_escape(const char *p) { /* The return value of this function (unlike cg_unescape()) * needs free()! */ - if (p[0] == '_' || streq(p, "notify_on_release") || streq(p, "release_agent") || streq(p, "tasks")) + if (p[0] == 0 || + p[0] == '_' || + p[0] == '.' || + streq(p, "notify_on_release") || + streq(p, "release_agent") || + streq(p, "tasks")) need_prefix = true; else { const char *dot;