diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-04-22 23:10:13 -0300 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-04-22 23:14:12 -0300 |
commit | ae018d9bc900d6355dea4af05119b49c67945184 (patch) | |
tree | 07a311ae16ac331f1044503bbb01a4e111331fb2 /src/core/unit.c | |
parent | cd8f53ab1601513cc3407447bfe3359ee7139676 (diff) |
cgroup: make sure all our cgroup objects have a suffix and are properly escaped
Session objects will now get the .session suffix, user objects the .user
suffix, nspawn containers the .nspawn suffix.
This also changes the user cgroups to be named after the numeric UID
rather than the username, since this allows us the parse these paths
standalone without requiring access to the cgroup file system.
This also changes the mapping of instanced units to cgroups. Instead of
mapping foo@bar.service to the cgroup path /user/foo@.service/bar we
will now map it to /user/foo@.service/foo@bar.service, in order to
ensure that all our objects are properly suffixed in the tree.
Diffstat (limited to 'src/core/unit.c')
-rw-r--r-- | src/core/unit.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/core/unit.c b/src/core/unit.c index 2525f49980..5834009445 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1810,14 +1810,13 @@ static const char *resolve_template(Unit *u, const char *name, const char*path, if (u->instance) s = unit_name_replace_instance(name, u->instance); else { - char *i; + _cleanup_free_ char *i = NULL; i = unit_name_to_prefix(u->id); if (!i) return NULL; s = unit_name_replace_instance(name, i); - free(i); } if (!s) @@ -1972,15 +1971,30 @@ char *unit_default_cgroup_path(Unit *u) { assert(u); if (u->instance) { - _cleanup_free_ char *t = NULL; + _cleanup_free_ char *t = NULL, *escaped_template = NULL, *escaped_instance = NULL; t = unit_name_template(u->id); if (!t) return NULL; - return strjoin(u->manager->cgroup_hierarchy, "/", t, "/", u->instance, NULL); - } else - return strjoin(u->manager->cgroup_hierarchy, "/", u->id, NULL); + escaped_template = cg_escape(t); + if (!escaped_template) + return NULL; + + escaped_instance = cg_escape(u->id); + if (!escaped_instance) + return NULL; + + return strjoin(u->manager->cgroup_hierarchy, "/", escaped_template, "/", escaped_instance, NULL); + } else { + _cleanup_free_ char *escaped = NULL; + + escaped = cg_escape(u->id); + if (!escaped) + return NULL; + + return strjoin(u->manager->cgroup_hierarchy, "/", escaped, NULL); + } } int unit_add_cgroup_from_text(Unit *u, const char *name, bool overwrite, CGroupBonding **ret) { |