X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftarget.c;h=f8df6fb757742d3cb8f166d63c582ef3f563e8a1;hb=4627d39661ffcdd11e814650dfcc9ac3d0d0ec0b;hp=d3f3748cd54f86057b73d6e07f2bbe13784cb63f;hpb=514f4ef52f91edb3741cad88d34572d162459346;p=elogind.git diff --git a/src/target.c b/src/target.c index d3f3748cd..f8df6fb75 100644 --- a/src/target.c +++ b/src/target.c @@ -43,13 +43,53 @@ static void target_set_state(Target *t, TargetState state) { if (state != old_state) log_debug("%s changed %s -> %s", - UNIT(t)->meta.id, + t->meta.id, target_state_to_string(old_state), target_state_to_string(state)); unit_notify(UNIT(t), state_translation_table[old_state], state_translation_table[state]); } +static int target_add_default_dependencies(Target *t) { + Iterator i; + Unit *other; + int r; + + /* Imply ordering for requirement dependencies + * on target units. */ + + SET_FOREACH(other, t->meta.dependencies[UNIT_REQUIRES], i) + if ((r = unit_add_dependency(UNIT(t), UNIT_AFTER, other, true)) < 0) + return r; + SET_FOREACH(other, t->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i) + if ((r = unit_add_dependency(UNIT(t), UNIT_AFTER, other, true)) < 0) + return r; + SET_FOREACH(other, t->meta.dependencies[UNIT_WANTS], i) + if ((r = unit_add_dependency(UNIT(t), UNIT_AFTER, other, true)) < 0) + return r; + + return 0; +} + +static int target_load(Unit *u) { + Target *t = TARGET(u); + int r; + + assert(t); + + if ((r = unit_load_fragment_and_dropin(u)) < 0) + return r; + + /* This is a new unit? Then let's add in some extras */ + if (u->meta.load_state == UNIT_LOADED) { + if (u->meta.default_dependencies) + if ((r = target_add_default_dependencies(t)) < 0) + return r; + } + + return 0; +} + static int target_coldplug(Unit *u) { Target *t = TARGET(u); @@ -177,7 +217,7 @@ DEFINE_STRING_TABLE_LOOKUP(target_state, TargetState); const UnitVTable target_vtable = { .suffix = ".target", - .load = unit_load_fragment_and_dropin, + .load = target_load, .coldplug = target_coldplug, .dump = target_dump,