]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/unit: add one assertion, reduce variable scope
authorMike Yuan <me@yhndnzj.com>
Mon, 3 Jun 2024 04:11:02 +0000 (06:11 +0200)
committerMike Yuan <me@yhndnzj.com>
Sun, 9 Jun 2024 12:41:44 +0000 (14:41 +0200)
src/core/unit.c

index 2d40618fcbb7ad201d33f65c6636e0165f58c9c5..2da5876237a0178636bc6c7e54ced1aeddda2ebc 100644 (file)
@@ -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);