From b984151e502ffbc31c61eb9eec5f2046d77608df Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sun, 9 Jun 2024 14:48:37 +0200 Subject: [PATCH] core/unit: merge nested if statements, use else where appropriate We already use `else if` for unit state checks above. Let's use that at one more place to make mutually exclusive cases more distinct. --- src/core/unit.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/core/unit.c b/src/core/unit.c index 2da5876237..a11c075c7f 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2611,17 +2611,16 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su * the bus queue, so that any job change signal queued will force out the unit change signal first. */ unit_add_to_dbus_queue(u); - /* Update systemd-oomd on the property/state change */ - if (os != ns) { - /* Always send an update if the unit is going into an inactive state so systemd-oomd knows to stop - * monitoring. - * Also send an update whenever the unit goes active; this is to handle a case where an override file - * sets one of the ManagedOOM*= properties to "kill", then later removes it. systemd-oomd needs to - * know to stop monitoring when the unit changes from "kill" -> "auto" on daemon-reload, but we don't - * have the information on the property. Thus, indiscriminately send an update. */ - if (UNIT_IS_INACTIVE_OR_FAILED(ns) || UNIT_IS_ACTIVE_OR_RELOADING(ns)) - (void) manager_varlink_send_managed_oom_update(u); - } + /* Update systemd-oomd on the property/state change. + * + * Always send an update if the unit is going into an inactive state so systemd-oomd knows to + * stop monitoring. + * Also send an update whenever the unit goes active; this is to handle a case where an override file + * sets one of the ManagedOOM*= properties to "kill", then later removes it. systemd-oomd needs to + * know to stop monitoring when the unit changes from "kill" -> "auto" on daemon-reload, but we don't + * have the information on the property. Thus, indiscriminately send an update. */ + if (os != ns && (UNIT_IS_INACTIVE_OR_FAILED(ns) || UNIT_IS_ACTIVE_OR_RELOADING(ns))) + (void) manager_varlink_send_managed_oom_update(u); /* Update timestamps for state changes */ if (!MANAGER_IS_RELOADING(m)) { @@ -2734,9 +2733,8 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su /* Maybe we can release some resources now? */ unit_submit_to_release_resources_queue(u); - } - if (UNIT_IS_ACTIVE_OR_RELOADING(ns)) { + } else if (UNIT_IS_ACTIVE_OR_RELOADING(ns)) { /* Start uphold units regardless if going up was expected or not */ check_uphold_dependencies(u);