chiark / gitweb /
socket: fix output of TCP congestion options
[elogind.git] / src / unit.c
index 001d7659c430d745e26881890bc9f40ab6b5fe1c..ca15c257e8aaff591be7266fc502af2808dbeb91 100644 (file)
@@ -440,6 +440,7 @@ static void merge_dependencies(Unit *u, Unit *other, UnitDependency d) {
         assert(other);
         assert(d < _UNIT_DEPENDENCY_MAX);
 
+        /* Fix backwards pointers */
         SET_FOREACH(back, other->meta.dependencies[d], i) {
                 UnitDependency k;
 
@@ -725,6 +726,42 @@ int unit_load_fragment_and_dropin_optional(Unit *u) {
         return 0;
 }
 
+static int unit_add_one_default_dependency(Unit *u, Unit *target) {
+        assert(u);
+        assert(target);
+
+        if (target->meta.type != UNIT_TARGET)
+                return 0;
+
+        /* Don't create loops */
+        if (set_get(target->meta.dependencies[UNIT_BEFORE], u))
+                return 0;
+
+        return unit_add_dependency(target, UNIT_AFTER, u, true);
+}
+
+static int unit_add_default_dependencies(Unit *u) {
+        Unit *other;
+        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)
+                        return r;
+
+        SET_FOREACH(other, u->meta.dependencies[UNIT_REQUIRED_BY_OVERRIDABLE], i)
+                if ((r = unit_add_one_default_dependency(u, other)) < 0)
+                        return r;
+
+        SET_FOREACH(other, u->meta.dependencies[UNIT_WANTED_BY], i)
+                if ((r = unit_add_one_default_dependency(u, other)) < 0)
+                        return r;
+
+        return 0;
+}
+
 int unit_load(Unit *u) {
         int r;
 
@@ -750,6 +787,11 @@ int unit_load(Unit *u) {
                 goto fail;
         }
 
+        if (u->meta.load_state == UNIT_LOADED &&
+            u->meta.default_dependencies)
+                if ((r = unit_add_default_dependencies(u)) < 0)
+                        goto fail;
+
         assert((u->meta.load_state != UNIT_MERGED) == !u->meta.merged_into);
 
         unit_add_to_dbus_queue(unit_follow_merge(u));