From f6f271f0db802c628f95d853ceb4f1ef254d4a74 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 3 Jun 2024 06:11:02 +0200 Subject: [PATCH] core/unit: add one assertion, reduce variable scope --- src/core/unit.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/unit.c b/src/core/unit.c index 2d40618fcb..2da5876237 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2597,9 +2597,6 @@ static bool unit_process_job(Job *j, UnitActiveState ns, bool reload_success) { } void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success) { - const char *reason; - Manager *m; - assert(u); assert(os < _UNIT_ACTIVE_STATE_MAX); assert(ns < _UNIT_ACTIVE_STATE_MAX); @@ -2608,7 +2605,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su * UnitActiveState! That means that ns == os is an expected behavior here. For example: if a mount point is * remounted this function will be called too! */ - m = u->manager; + Manager *m = ASSERT_PTR(u->manager); /* Let's enqueue the change signal early. In case this unit has a job associated we want that this unit is in * the bus queue, so that any job change signal queued will force out the unit change signal first. */ @@ -2707,6 +2704,8 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su unit_trigger_notify(u); if (!MANAGER_IS_RELOADING(m)) { + const char *reason; + if (os != UNIT_FAILED && ns == UNIT_FAILED) { reason = strjoina("unit ", u->id, " failed"); emergency_action(m, u->failure_action, 0, u->reboot_arg, unit_failure_action_exit_status(u), reason);