core: generalize the cgroup empty check on GC
Let's move the cgroup empty check for all unit types into the generic unit_check_gc() call, out of the per-unit-type _check_gc() type. This not only allows us to share some code, but also hooks up mount and socket units with this kind of check, for free, as it was missing there previously.
This commit is contained in:
@@ -334,6 +334,7 @@ int unit_set_description(Unit *u, const char *description) {
|
||||
|
||||
bool unit_check_gc(Unit *u) {
|
||||
UnitActiveState state;
|
||||
int r;
|
||||
|
||||
assert(u);
|
||||
|
||||
@@ -381,6 +382,17 @@ bool unit_check_gc(Unit *u) {
|
||||
assert_not_reached("Unknown garbage collection mode");
|
||||
}
|
||||
|
||||
if (u->cgroup_path) {
|
||||
/* If the unit has a cgroup, then check whether there's anything in it. If so, we should stay
|
||||
* around. Units with active processes should never be collected. */
|
||||
|
||||
r = cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path);
|
||||
if (r < 0)
|
||||
log_unit_debug_errno(u, r, "Failed to determine whether cgroup %s is empty: %m", u->cgroup_path);
|
||||
if (r <= 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (UNIT_VTABLE(u)->check_gc)
|
||||
if (UNIT_VTABLE(u)->check_gc(u))
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user