]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/unit: place OnFailure= handling close to OnSuccess=
authorMike Yuan <me@yhndnzj.com>
Mon, 3 Jun 2024 04:15:15 +0000 (06:15 +0200)
committerMike Yuan <me@yhndnzj.com>
Sun, 9 Jun 2024 12:52:11 +0000 (14:52 +0200)
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

index a11c075c7fc57311a6fdfed3a6107ffae05c9c10..def621ef6d11c6f824d0200bc6642a5b7c3c34c2 100644 (file)
@@ -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);