core/unit: place OnFailure= handling close to OnSuccess=

While at it, the duplicate log of "Unit entered failed state"
is dropped. Since the state change would be logged by each
unit type already, before calling unit_notify().
This commit is contained in:
Mike Yuan 2024-06-03 06:15:15 +02:00
parent b984151e50
commit 8c4514b258
No known key found for this signature in database
GPG key ID: 417471C0A40F58B3

View file

@ -2672,20 +2672,14 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
retroactively_stop_dependencies(u); retroactively_stop_dependencies(u);
} }
if (ns != os && ns == UNIT_FAILED) {
log_unit_debug(u, "Unit entered failed state.");
unit_start_on_failure(u, "OnFailure=", UNIT_ATOM_ON_FAILURE, u->on_failure_job_mode);
}
if (UNIT_IS_ACTIVE_OR_RELOADING(ns) && !UNIT_IS_ACTIVE_OR_RELOADING(os)) { if (UNIT_IS_ACTIVE_OR_RELOADING(ns) && !UNIT_IS_ACTIVE_OR_RELOADING(os)) {
/* This unit just finished starting up */ /* This unit just finished starting up */
unit_emit_audit_start(u); unit_emit_audit_start(u);
manager_send_unit_plymouth(m, u); manager_send_unit_plymouth(m, u);
manager_send_unit_supervisor(m, u, /* active= */ true); manager_send_unit_supervisor(m, u, /* active= */ true);
}
if (UNIT_IS_INACTIVE_OR_FAILED(ns) && !UNIT_IS_INACTIVE_OR_FAILED(os)) { } else if (UNIT_IS_INACTIVE_OR_FAILED(ns) && !UNIT_IS_INACTIVE_OR_FAILED(os)) {
/* This unit just stopped/failed. */ /* This unit just stopped/failed. */
unit_emit_audit_stop(u, ns); unit_emit_audit_stop(u, ns);
@ -2695,6 +2689,8 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
if (ns == UNIT_INACTIVE && !IN_SET(os, UNIT_FAILED, UNIT_INACTIVE, UNIT_MAINTENANCE)) if (ns == UNIT_INACTIVE && !IN_SET(os, UNIT_FAILED, UNIT_INACTIVE, UNIT_MAINTENANCE))
unit_start_on_failure(u, "OnSuccess=", UNIT_ATOM_ON_SUCCESS, u->on_success_job_mode); unit_start_on_failure(u, "OnSuccess=", UNIT_ATOM_ON_SUCCESS, u->on_success_job_mode);
else if (ns != os && ns == UNIT_FAILED)
unit_start_on_failure(u, "OnFailure=", UNIT_ATOM_ON_FAILURE, u->on_failure_job_mode);
} }
manager_recheck_journal(m); manager_recheck_journal(m);