From 8c4514b258f35b9e9a05dd483b7605adac732b6f Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 3 Jun 2024 06:15:15 +0200 Subject: [PATCH] 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(). --- src/core/unit.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/core/unit.c b/src/core/unit.c index a11c075c7f..def621ef6d 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2672,20 +2672,14 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su 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)) { /* This unit just finished starting up */ unit_emit_audit_start(u); manager_send_unit_plymouth(m, u); 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. */ 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)) 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);