[systemd-commits] 2 commits - src/unit.c

Michal Schmidt michich at kemper.freedesktop.org
Fri Dec 9 06:41:18 PST 2011


 src/unit.c |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

New commits:
commit cd0504d0a13d8297b97c9238fd1b94b4141c5aa8
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Fri Dec 9 15:25:29 2011 +0100

    unit: check for unneeded dependencies even when unit stop was expected
    
    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

diff --git a/src/unit.c b/src/unit.c
index 56137d7..03c90f5 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -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);

commit f60c2665f9ba1dd4a6b4a36b2e8195482ada9957
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Fri Dec 9 15:24:04 2011 +0100

    unit: fix false positive in check for unneeded unit
    
    A freshly started unit A was immediately considered unneeded just because
    unit B, which Requires A, was starting later in the transaction.
    Fix it by looking not only at the state of B, but also at its pending job.
    
    Also fix a copied&pasted comment.

diff --git a/src/unit.c b/src/unit.c
index 018e986..56137d7 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -1032,19 +1032,19 @@ static void unit_check_unneeded(Unit *u) {
                 return;
 
         SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
-                if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
+                if (unit_pending_active(other))
                         return;
 
         SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i)
-                if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
+                if (unit_pending_active(other))
                         return;
 
         SET_FOREACH(other, u->meta.dependencies[UNIT_WANTED_BY], i)
-                if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
+                if (unit_pending_active(other))
                         return;
 
         SET_FOREACH(other, u->meta.dependencies[UNIT_BOUND_BY], i)
-                if (!UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(other)))
+                if (unit_pending_active(other))
                         return;
 
         log_info("Service %s is not needed anymore. Stopping.", u->meta.id);
@@ -2518,7 +2518,7 @@ bool unit_pending_inactive(Unit *u) {
 bool unit_pending_active(Unit *u) {
         assert(u);
 
-        /* Returns true if the unit is inactive or going down */
+        /* Returns true if the unit is active or going up */
 
         if (UNIT_IS_ACTIVE_OR_ACTIVATING(unit_active_state(u)))
                 return true;



More information about the systemd-commits mailing list