[systemd-commits] src/target.c src/unit.c src/unit.h

Lennart Poettering lennart at kemper.freedesktop.org
Mon Sep 13 16:51:39 PDT 2010


 src/target.c |   21 +++++++++++++++++++++
 src/unit.c   |   22 ++++++++++++++--------
 src/unit.h   |    2 ++
 3 files changed, 37 insertions(+), 8 deletions(-)

New commits:
commit bba34eedc7fb8f5023fa0d55c23d00d5854546c5
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Sep 14 01:51:30 2010 +0200

    target: add implicit target/unit ordering deps only if both sides have been fully loaded

diff --git a/src/target.c b/src/target.c
index f1f656e..3522bf1 100644
--- a/src/target.c
+++ b/src/target.c
@@ -53,8 +53,29 @@ static void target_set_state(Target *t, TargetState state) {
 }
 
 static int target_add_default_dependencies(Target *t) {
+        Iterator i;
+        Unit *other;
+        int r;
+
         assert(t);
 
+        /* Imply ordering for requirement dependencies on target
+         * units. Note that when the user created a contradicting
+         * ordering manually we won't add anything in here to make
+         * sure we don't create a loop. */
+
+        SET_FOREACH(other, t->meta.dependencies[UNIT_REQUIRES], i)
+                if ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
+                    return r;
+
+        SET_FOREACH(other, t->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
+                if ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
+                    return r;
+
+        SET_FOREACH(other, t->meta.dependencies[UNIT_WANTS], i)
+                if ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
+                    return r;
+
         /* Make sure targets are unloaded on shutdown */
         return unit_add_dependency_by_name(UNIT(t), UNIT_CONFLICTED_BY, SPECIAL_SHUTDOWN_TARGET, NULL, true);
 }
diff --git a/src/unit.c b/src/unit.c
index ca15c25..5a451c5 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -726,13 +726,19 @@ int unit_load_fragment_and_dropin_optional(Unit *u) {
         return 0;
 }
 
-static int unit_add_one_default_dependency(Unit *u, Unit *target) {
+int unit_add_default_target_dependency(Unit *u, Unit *target) {
         assert(u);
         assert(target);
 
         if (target->meta.type != UNIT_TARGET)
                 return 0;
 
+        /* Only add the dependency if boths units are loaded, so that
+         * that loop check below is reliable */
+        if (u->meta.load_state != UNIT_LOADED ||
+            target->meta.load_state != UNIT_LOADED)
+                return 0;
+
         /* Don't create loops */
         if (set_get(target->meta.dependencies[UNIT_BEFORE], u))
                 return 0;
@@ -741,22 +747,22 @@ static int unit_add_one_default_dependency(Unit *u, Unit *target) {
 }
 
 static int unit_add_default_dependencies(Unit *u) {
-        Unit *other;
+        Unit *target;
         Iterator i;
         int r;
 
         assert(u);
 
-        SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY], i)
-                if ((r = unit_add_one_default_dependency(u, other)) < 0)
+        SET_FOREACH(target, u->meta.dependencies[UNIT_REQUIRED_BY], i)
+                if ((r = unit_add_default_target_dependency(u, target)) < 0)
                         return r;
 
-        SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i)
-                if ((r = unit_add_one_default_dependency(u, other)) < 0)
+        SET_FOREACH(target, u->meta.dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i)
+                if ((r = unit_add_default_target_dependency(u, target)) < 0)
                         return r;
 
-        SET_FOREACH(other, u->meta.dependencies[UNIT_WANTED_BY], i)
-                if ((r = unit_add_one_default_dependency(u, other)) < 0)
+        SET_FOREACH(target, u->meta.dependencies[UNIT_WANTED_BY], i)
+                if ((r = unit_add_default_target_dependency(u, target)) < 0)
                         return r;
 
         return 0;
diff --git a/src/unit.h b/src/unit.h
index c93f3f7..20bb6a2 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -501,6 +501,8 @@ Unit *unit_following(Unit *u);
 
 bool unit_pending_inactive(Unit *u);
 
+int unit_add_default_target_dependency(Unit *u, Unit *target);
+
 const char *unit_load_state_to_string(UnitLoadState i);
 UnitLoadState unit_load_state_from_string(const char *s);
 


More information about the systemd-commits mailing list