]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: Handle cgroup pruning in on_cgroup_empty_event
authorRichard Phibel <rphibel@googlemail.com>
Thu, 25 May 2023 17:49:11 +0000 (19:49 +0200)
committerRichard Phibel <rphibel@googlemail.com>
Mon, 29 May 2023 11:26:16 +0000 (13:26 +0200)
This change removes the pruning of cgroups for FAILED/INACTIVE units
from per-unit-type handlers and moves it in on_cgroup_empty_event.

src/core/cgroup.c
src/core/scope.c
src/core/service.c

index 4ec5dfa587f33f77d8cbb8dbd443e78cd77b5af9..839b1676c88a29b5f5fde28a71b77cafa9a8ee6e 100644 (file)
@@ -3142,7 +3142,9 @@ static int on_cgroup_empty_event(sd_event_source *s, void *userdata) {
 
         unit_add_to_gc_queue(u);
 
-        if (UNIT_VTABLE(u)->notify_cgroup_empty)
+        if (IN_SET(unit_active_state(u), UNIT_INACTIVE, UNIT_FAILED))
+                unit_prune_cgroup(u);
+        else if (UNIT_VTABLE(u)->notify_cgroup_empty)
                 UNIT_VTABLE(u)->notify_cgroup_empty(u);
 
         return 0;
index 761eb5ea56e696eb730debd4dd395fad95037f3e..72253421e232b94bd24bbef6123700e064632e9e 100644 (file)
@@ -629,11 +629,6 @@ 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_notify_cgroup_oom_event(Unit *u, bool managed_oom) {
index 533d7d3771a252b34bbebcef2f09c70442f9c5a8..38f87456749af8f20c9c136b8e110507ae58237d 100644 (file)
@@ -3648,12 +3648,7 @@ static void service_notify_cgroup_empty_event(Unit *u) {
 
         /* 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. */
-        case SERVICE_DEAD:
-        case SERVICE_FAILED:
-        case SERVICE_DEAD_BEFORE_AUTO_RESTART:
-        case SERVICE_FAILED_BEFORE_AUTO_RESTART:
         case SERVICE_AUTO_RESTART:
-        case SERVICE_DEAD_RESOURCES_PINNED:
                 unit_prune_cgroup(u);
                 break;