return 0;
}
+static bool unit_success_failure_handler_has_jobs(Unit *unit) {
+ Unit *other;
+
+ UNIT_FOREACH_DEPENDENCY(other, unit, UNIT_ATOM_ON_SUCCESS)
+ if (other->job || other->nop_job)
+ return true;
+
+ UNIT_FOREACH_DEPENDENCY(other, unit, UNIT_ATOM_ON_FAILURE)
+ if (other->job || other->nop_job)
+ return true;
+
+ return false;
+}
+
bool unit_may_gc(Unit *u) {
UnitActiveState state;
int r;
* in unit_gc_sweep(), but using markers to properly collect dependency loops.
*/
- if (u->job)
- return false;
-
- if (u->nop_job)
+ if (u->job || u->nop_job)
return false;
state = unit_active_state(u);
assert_not_reached();
}
+ /* Check if any OnFailure= or on Success= jobs may be pending */
+ if (unit_success_failure_handler_has_jobs(u))
+ return false;
+
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. */