core/unit: add one assertion, reduce variable scope

This commit is contained in:
Mike Yuan 2024-06-03 06:11:02 +02:00
parent aa7f2246ba
commit f6f271f0db
No known key found for this signature in database
GPG key ID: 417471C0A40F58B3

View 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) { void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_success) {
const char *reason;
Manager *m;
assert(u); assert(u);
assert(os < _UNIT_ACTIVE_STATE_MAX); assert(os < _UNIT_ACTIVE_STATE_MAX);
assert(ns < _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 * 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! */ * 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 /* 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. */ * 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); unit_trigger_notify(u);
if (!MANAGER_IS_RELOADING(m)) { if (!MANAGER_IS_RELOADING(m)) {
const char *reason;
if (os != UNIT_FAILED && ns == UNIT_FAILED) { if (os != UNIT_FAILED && ns == UNIT_FAILED) {
reason = strjoina("unit ", u->id, " failed"); reason = strjoina("unit ", u->id, " failed");
emergency_action(m, u->failure_action, 0, u->reboot_arg, unit_failure_action_exit_status(u), reason); emergency_action(m, u->failure_action, 0, u->reboot_arg, unit_failure_action_exit_status(u), reason);