X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Funit.c;h=5a451c57c2a038c1cc297c7d3658f96527ab206e;hp=d28a0a8cf7637b461ebbe8334bc6f82a22e7ce46;hb=c1480dae170e5b597b937dc3591974dc76728680;hpb=98bc20006d89aa8e7d9d3eeb75f475a66943fe55 diff --git a/src/unit.c b/src/unit.c index d28a0a8cf..5a451c57c 100644 --- a/src/unit.c +++ b/src/unit.c @@ -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,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; @@ -740,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;