chiark / gitweb /
core: do not add dependencies to self
[elogind.git] / src / core / unit.c
index b68796a..0926732 100644 (file)
@@ -597,14 +597,22 @@ static void merge_dependencies(Unit *u, Unit *other, UnitDependency d) {
                 UnitDependency k;
 
                 for (k = 0; k < _UNIT_DEPENDENCY_MAX; k++) {
-                        r = set_remove_and_put(back->dependencies[k], other, u);
-                        if (r == -EEXIST)
+                        /* Do not add dependencies between u and itself */
+                        if (back == u) {
                                 set_remove(back->dependencies[k], other);
-                        else
-                                assert(r >= 0 || r == -ENOENT);
+                        } else {
+                                r = set_remove_and_put(back->dependencies[k], other, u);
+                                if (r == -EEXIST)
+                                        set_remove(back->dependencies[k], other);
+                                else
+                                        assert(r >= 0 || r == -ENOENT);
+                        }
                 }
         }
 
+        /* Also do not move dependencies on u to itself */
+        set_remove(other->dependencies[d], u);
+
         complete_move(&u->dependencies[d], &other->dependencies[d]);
 
         set_free(other->dependencies[d]);