Skip to content

Commit

Permalink
core: Handle cgroup pruning in on_cgroup_empty_event
Browse files Browse the repository at this point in the history
This change removes the pruning of cgroups for FAILED/INACTIVE units
from per-unit-type handlers and moves it in on_cgroup_empty_event.
  • Loading branch information
rphibel committed May 29, 2023
1 parent 8db9989 commit 380dd17
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/core/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/core/scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions src/core/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 380dd17

Please sign in to comment.