]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/core/scope.c
core: clean up inactive/failed {service|scope}'s cgroups when the last process exits
[thirdparty/systemd.git] / src / core / scope.c
index 540c83ba451b6ab75dc162753f410123276c02e4..13cd2e6c3c2aeed9cf4ce6a0056cf0d9393298d3 100644 (file)
@@ -487,6 +487,11 @@ static void scope_notify_cgroup_empty_event(Unit *u) {
 
         if (IN_SET(s->state, SCOPE_RUNNING, SCOPE_ABANDONED, SCOPE_STOP_SIGTERM, SCOPE_STOP_SIGKILL))
                 scope_enter_dead(s, SCOPE_SUCCESS);
+
+        /* If the cgroup empty notification comes when the unit is not active, we must have failed to clean
+         * up the cgroup earlier and should do it now. */
+        if (IN_SET(s->state, SCOPE_DEAD, SCOPE_FAILED))
+                unit_prune_cgroup(u);
 }
 
 static void scope_sigchld_event(Unit *u, pid_t pid, int code, int status) {