chiark / gitweb /
unit: check for unneeded dependencies even when unit stop was expected
authorMichal Schmidt <mschmidt@redhat.com>
Fri, 9 Dec 2011 14:25:29 +0000 (15:25 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Fri, 9 Dec 2011 14:25:29 +0000 (15:25 +0100)
systemd did not stop units marked as "StopWhenUnneeded=yes" when the requiring
unit was stopped on user's request.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=704197
src/unit.c

index 56137d7bd14c60ae423c80884d0cb48a5dd536aa..03c90f5874908335b448f398e04b6d5e79339403 100644 (file)
@@ -1105,6 +1105,14 @@ static void retroactively_stop_dependencies(Unit *u) {
         SET_FOREACH(other, u->meta.dependencies[UNIT_BOUND_BY], i)
                 if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
                         manager_add_job(u->meta.manager, JOB_STOP, other, JOB_REPLACE, true, NULL, NULL);
+}
+
+static void check_unneeded_dependencies(Unit *u) {
+        Iterator i;
+        Unit *other;
+
+        assert(u);
+        assert(UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u)));
 
         /* Garbage collect services that might not be needed anymore, if enabled */
         SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRES], i)
@@ -1263,6 +1271,10 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
                                 retroactively_stop_dependencies(u);
                 }
 
+                /* stop unneeded units regardless if going down was expected or not */
+                if (UNIT_IS_ACTIVE_OR_ACTIVATING(os) && UNIT_IS_INACTIVE_OR_DEACTIVATING(ns))
+                        check_unneeded_dependencies(u);
+
                 if (ns != os && ns == UNIT_FAILED) {
                         log_notice("Unit %s entered failed state.", u->meta.id);
                         unit_trigger_on_failure(u);