[systemd-commits] 2 commits - man/daemon.xml src/target.c src/unit.c

Lennart Poettering lennart at kemper.freedesktop.org
Mon Sep 13 03:07:00 PDT 2010


 man/daemon.xml |   10 +++++-----
 src/target.c   |   22 +---------------------
 src/unit.c     |   41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 26 deletions(-)

New commits:
commit 98bc20006d89aa8e7d9d3eeb75f475a66943fe55
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Sep 13 12:06:49 2010 +0200

    target: add default unit ordering deps from the unit not the target

diff --git a/src/target.c b/src/target.c
index 1118693..f1f656e 100644
--- a/src/target.c
+++ b/src/target.c
@@ -53,27 +53,7 @@ static void target_set_state(Target *t, TargetState state) {
 }
 
 static int target_add_default_dependencies(Target *t) {
-        Iterator i;
-        Unit *other;
-        int r;
-
-        /* Imply ordering for requirement dependencies on target
-         * units. Note that when the user created a contradicting
-         * ordering manually we won't add anything in here to make
-         * sure we don't create a loop. */
-
-        SET_FOREACH(other, t->meta.dependencies[UNIT_REQUIRES], i)
-                if (!set_get(t->meta.dependencies[UNIT_BEFORE], other))
-                        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 (!set_get(t->meta.dependencies[UNIT_BEFORE], other))
-                        if ((r = unit_add_dependency(UNIT(t), UNIT_AFTER, other, true)) < 0)
-                                return r;
-        SET_FOREACH(other, t->meta.dependencies[UNIT_WANTS], i)
-                if (!set_get(t->meta.dependencies[UNIT_BEFORE], other))
-                        if ((r = unit_add_dependency(UNIT(t), UNIT_AFTER, other, true)) < 0)
-                                return r;
+        assert(t);
 
         /* Make sure targets are unloaded on shutdown */
         return unit_add_dependency_by_name(UNIT(t), UNIT_CONFLICTED_BY, SPECIAL_SHUTDOWN_TARGET, NULL, true);
diff --git a/src/unit.c b/src/unit.c
index 001d765..d28a0a8 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -725,6 +725,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 +786,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));
commit 34f0c1a118c68bbf8c6b57006c2acee2eedd1cbd
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Sep 13 12:05:54 2010 +0200

    man: some clarifications

diff --git a/man/daemon.xml b/man/daemon.xml
index fdc6a64..edf8e52 100644
--- a/man/daemon.xml
+++ b/man/daemon.xml
@@ -826,7 +826,7 @@ endif</programlisting>
 
                         <programlisting>%post
 if [ $1 -eq 1 ]; then
-        # Enable (but don't start) the units by default
+        # On install, enable (but don't start) the units by default
         /bin/systemctl enable foobar.service foobar.socket >/dev/null 2>&amp;1 || :
 
         # Alternatively, just call /bin/systemctl daemon-reload here,
@@ -836,16 +836,16 @@ fi
 
 %preun
 if [ $1 -eq 0 ]; then
-        # Disable and stop the units
+        # On uninstall, disable and stop the units
         /bin/systemctl disable foobar.service foobar.socket >/dev/null 2>&amp;1 || :
         /bin/systemctl stop foobar.service foobar.socket >/dev/null 2>&amp;1 || :
 fi
 
 %postun
+# On upgrade and uninstall, reload init system configuration, to make systemd honour changed unit files
+/bin/systemctl daemon-reload >/dev/null 2>&amp;1 || :
 if [ $1 -ge 1 ] ; then
-        # On upgrade, reload init system configuration if we changed unit files
-        /bin/systemctl daemon-reload >/dev/null 2>&amp;1 || :
-        # On upgrade, restart the daemon
+        # Optionally, on upgrade, restart the daemon
         /bin/systemctl try-restart foobar.service >/dev/null 2>&amp;1 || :
 fi</programlisting>
 


More information about the systemd-commits mailing list