summaryrefslogtreecommitdiff
path: root/src/target.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-07-03 19:48:33 +0200
committerLennart Poettering <lennart@poettering.net>2010-07-03 19:48:33 +0200
commita40eb73224e237f758d38847ae216c019425ebac (patch)
treedc95aa3e1800bb44f43393341acb469863483036 /src/target.c
parent2c966c038dc32ef39baa176371395cde4e541d01 (diff)
unit: add DefaultDependencies= setting
In order to simplify writing of unit files introduce default dependencies that are added to all units unless explictly disabled in a unit. This option can be switched off for select units that are involved in early boot-up ot late system shutdown, This should simplify service files for most normal daemons, but breaks existing service files for software involved in early boot (notably udev), which need to be updated for a DefaultDependencies=no setting)
Diffstat (limited to 'src/target.c')
-rw-r--r--src/target.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/target.c b/src/target.c
index fba99568a3..f8df6fb757 100644
--- a/src/target.c
+++ b/src/target.c
@@ -50,6 +50,46 @@ static void target_set_state(Target *t, TargetState 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,