summaryrefslogtreecommitdiff
path: root/src/core/slice.c
diff options
context:
space:
mode:
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>2018-02-04 20:46:27 +0000
committerAlan Jenkins <alan.christopher.jenkins@gmail.com>2018-02-04 22:51:34 +0000
commitd8e5a9338278d6602a0c552f01f298771a384798 (patch)
tree5cab4b27d3d020c4d937a0d585308ac44c4ba680 /src/core/slice.c
parent0c79456781ab649ef28c0343e4f42f0861d083ad (diff)
downloadsystemd-d8e5a9338278d6602a0c552f01f298771a384798.tar.gz
slice: system.slice should be perpetual like -.mount
`-.mount` is placed in `system.slice`, and hence depends on it. `-.mount` is always active and can never be stopped. Therefore the same should be true of `system.slice`. Synthesize it as perpetual (unless systemd is running as a user manager). Notice we also drop `Before=slices.target` as unnecessary. AFAICS the justification for `perpetual` is to provide extra protection against unintentionally stopping every single service. So adding system.slice to the perpetual units is perfectly consistent. I don't expect this will (or can) fix any other problem. And the `perpetual` protection probably isn't formal enough to spend much time thinking about. I've just noticed this a couple of times, as something that looks strange. Might be a bit surprising that we have user.slice on-disk but not system.slice, but I think it's ok. `systemctl status system.slice` will still point you towards `man systemd.special`. The only detail is that the system slice disables `DefaultDependencies`. If you're worrying about how system shutdown works when you read `man systemd.slice`, I think it is not too hard to guess that system.slice might do this: > Only slice units involved with early boot > or late system shutdown should disable this option (Docs are great. I really appreciate the systemd ones).
Diffstat (limited to 'src/core/slice.c')
-rw-r--r--src/core/slice.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/core/slice.c b/src/core/slice.c
index 0bbc0aedc5..ef2177279a 100644
--- a/src/core/slice.c
+++ b/src/core/slice.c
@@ -146,6 +146,29 @@ static int slice_load_root_slice(Unit *u) {
return 1;
}
+static int slice_load_system_slice(Unit *u) {
+ assert(u);
+
+ if (!MANAGER_IS_SYSTEM(u->manager))
+ return 0;
+ if (!unit_has_name(u, SPECIAL_SYSTEM_SLICE))
+ return 0;
+
+ u->perpetual = true;
+
+ /* The system slice is a bit special. For example it is always running and cannot be terminated. Because of its
+ * special semantics we synthesize it here, instead of relying on the unit file on disk. */
+
+ u->default_dependencies = false;
+
+ if (!u->description)
+ u->description = strdup("System Slice");
+ if (!u->documentation)
+ u->documentation = strv_new("man:systemd.special(7)", NULL);
+
+ return 1;
+}
+
static int slice_load(Unit *u) {
Slice *s = SLICE(u);
int r;
@@ -156,6 +179,10 @@ static int slice_load(Unit *u) {
r = slice_load_root_slice(u);
if (r < 0)
return r;
+ r = slice_load_system_slice(u);
+ if (r < 0)
+ return r;
+
r = unit_load_fragment_and_dropin_optional(u);
if (r < 0)
return r;
@@ -286,17 +313,17 @@ _pure_ static const char *slice_sub_state_to_string(Unit *u) {
return slice_state_to_string(SLICE(u)->state);
}
-static void slice_enumerate(Manager *m) {
+static void slice_enumerate_perpetual(Manager *m, const char *name) {
Unit *u;
int r;
assert(m);
- u = manager_get_unit(m, SPECIAL_ROOT_SLICE);
+ u = manager_get_unit(m, name);
if (!u) {
- r = unit_new_for_name(m, sizeof(Slice), SPECIAL_ROOT_SLICE, &u);
+ r = unit_new_for_name(m, sizeof(Slice), name, &u);
if (r < 0) {
- log_error_errno(r, "Failed to allocate the special " SPECIAL_ROOT_SLICE " unit: %m");
+ log_error_errno(r, "Failed to allocate the special %s unit: %m", name);
return;
}
}
@@ -308,6 +335,15 @@ static void slice_enumerate(Manager *m) {
unit_add_to_dbus_queue(u);
}
+static void slice_enumerate(Manager *m) {
+ assert(m);
+
+ slice_enumerate_perpetual(m, SPECIAL_ROOT_SLICE);
+
+ if (MANAGER_IS_SYSTEM(m))
+ slice_enumerate_perpetual(m, SPECIAL_SYSTEM_SLICE);
+}
+
const UnitVTable slice_vtable = {
.object_size = sizeof(Slice),
.cgroup_context_offset = offsetof(Slice, cgroup_context),