summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-07-11 03:52:43 +0200
committerLennart Poettering <lennart@poettering.net>2013-07-11 18:49:52 +0200
commita8833944647bfd10e43569646be954db5cbac54e (patch)
treec9f707d3ede6a9f4e300b0034d69766c61efc4c2 /src
parente2ca86cf78f911a8be51f0224796e24883019139 (diff)
core: implicitly create a per-template slice for all instantiated units by default
If no explicit slice is configured for an instantiated unit, create an implicit one for all instances of the same template.
Diffstat (limited to 'src')
-rw-r--r--src/core/unit.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/core/unit.c b/src/core/unit.c
index 5bc57e25c6..bfde08d68c 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2030,6 +2030,8 @@ char *unit_default_cgroup_path(Unit *u) {
}
int unit_add_default_slice(Unit *u) {
+ _cleanup_free_ char *b = NULL;
+ const char *slice_name;
Unit *slice;
int r;
@@ -2041,7 +2043,38 @@ int unit_add_default_slice(Unit *u) {
if (!unit_get_cgroup_context(u))
return 0;
- r = manager_load_unit(u->manager, u->manager->running_as == SYSTEMD_SYSTEM ? SPECIAL_SYSTEM_SLICE : SPECIAL_ROOT_SLICE, NULL, NULL, &slice);
+ if (u->instance) {
+ _cleanup_free_ char *prefix = NULL, *escaped = NULL;
+ ;
+ /* Implicitly place all instantiated units in their
+ * own per-template slice */
+
+ prefix = unit_name_to_prefix(u->id);
+ if (!prefix)
+ return -ENOMEM;
+
+ /* The prefix is already escaped, but it might include
+ * "-" which has a special meaning for slice units,
+ * hence escape it here extra. */
+ escaped = strreplace(prefix, "-", "\\x2d");
+ if (!escaped)
+ return -ENOMEM;
+
+ if (u->manager->running_as == SYSTEMD_SYSTEM)
+ b = strjoin("system-", escaped, ".slice", NULL);
+ else
+ b = strappend(escaped, ".slice");
+ if (!b)
+ return -ENOMEM;
+
+ slice_name = b;
+ } else
+ slice_name =
+ u->manager->running_as == SYSTEMD_SYSTEM
+ ? SPECIAL_SYSTEM_SLICE
+ : SPECIAL_ROOT_SLICE;
+
+ r = manager_load_unit(u->manager, slice_name, NULL, NULL, &slice);
if (r < 0)
return r;