[systemd-commits] 4 commits - man/systemd.unit.xml src/condition.c src/condition.h src/dbus.h src/dbus-job.c src/dbus-unit.c src/load-fragment.c src/mount.c src/target.c src/unit.c TODO units/systemd-sysctl.service.in

Lennart Poettering lennart at kemper.freedesktop.org
Tue Mar 8 06:09:36 PST 2011


 TODO                            |    2 --
 man/systemd.unit.xml            |   21 ++++++++++++++++-----
 src/condition.c                 |   27 ++++++++++++++++++++-------
 src/condition.h                 |    6 ++++--
 src/dbus-job.c                  |    7 +++++--
 src/dbus-unit.c                 |    7 +++++--
 src/dbus.h                      |    8 ++++++++
 src/load-fragment.c             |   28 ++++++++++++++++++++--------
 src/mount.c                     |    8 ++++++--
 src/target.c                    |   25 ++++++++++++++-----------
 src/unit.c                      |   33 ++++++++++++++++++---------------
 units/systemd-sysctl.service.in |    4 ++--
 12 files changed, 118 insertions(+), 58 deletions(-)

New commits:
commit 21256a2b3be4f5fb12b68c47e570b865c5a631f8
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Mar 8 03:24:42 2011 +0100

    unit: don't accidently create ordering links to targets when default deps are off for either target and unit

diff --git a/src/target.c b/src/target.c
index 27b54e3..e61255c 100644
--- a/src/target.c
+++ b/src/target.c
@@ -53,9 +53,19 @@ static void target_set_state(Target *t, TargetState state) {
 }
 
 static int target_add_default_dependencies(Target *t) {
+        static const UnitDependency deps[] = {
+                UNIT_REQUIRES,
+                UNIT_REQUIRES_OVERRIDABLE,
+                UNIT_REQUISITE,
+                UNIT_REQUISITE_OVERRIDABLE,
+                UNIT_WANTS,
+                UNIT_BIND_TO
+        };
+
         Iterator i;
         Unit *other;
         int r;
+        unsigned k;
 
         assert(t);
 
@@ -64,17 +74,10 @@ static int target_add_default_dependencies(Target *t) {
          * 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 ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
-                    return r;
-
-        SET_FOREACH(other, t->meta.dependencies[UNIT_REQUIRES_OVERRIDABLE], i)
-                if ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
-                    return r;
-
-        SET_FOREACH(other, t->meta.dependencies[UNIT_WANTS], i)
-                if ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
-                    return r;
+        for (k = 0; k < ELEMENTSOF(deps); k++)
+                SET_FOREACH(other, t->meta.dependencies[deps[k]], i)
+                        if ((r = unit_add_default_target_dependency(other, UNIT(t))) < 0)
+                                return r;
 
         /* Make sure targets are unloaded on shutdown */
         return unit_add_dependency_by_name(UNIT(t), UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
diff --git a/src/unit.c b/src/unit.c
index 359cb2d..450b190 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -742,6 +742,12 @@ int unit_add_default_target_dependency(Unit *u, Unit *target) {
             target->meta.load_state != UNIT_LOADED)
                 return 0;
 
+        /* If either side wants no automatic dependencies, then let's
+         * skip this */
+        if (!u->meta.default_dependencies ||
+            target->meta.default_dependencies)
+                return 0;
+
         /* Don't create loops */
         if (set_get(target->meta.dependencies[UNIT_BEFORE], u))
                 return 0;
@@ -750,27 +756,24 @@ int unit_add_default_target_dependency(Unit *u, Unit *target) {
 }
 
 static int unit_add_default_dependencies(Unit *u) {
+        static const UnitDependency deps[] = {
+                UNIT_REQUIRED_BY,
+                UNIT_REQUIRED_BY_OVERRIDABLE,
+                UNIT_WANTED_BY,
+                UNIT_BOUND_BY
+        };
+
         Unit *target;
         Iterator i;
         int r;
+        unsigned k;
 
         assert(u);
 
-        SET_FOREACH(target, u->meta.dependencies[UNIT_REQUIRED_BY], i)
-                if ((r = unit_add_default_target_dependency(u, target)) < 0)
-                        return r;
-
-        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(target, u->meta.dependencies[UNIT_WANTED_BY], i)
-                if ((r = unit_add_default_target_dependency(u, target)) < 0)
-                        return r;
-
-        SET_FOREACH(target, u->meta.dependencies[UNIT_BOUND_BY], i)
-                if ((r = unit_add_default_target_dependency(u, target)) < 0)
-                        return r;
+        for (k = 0; k < ELEMENTSOF(deps); k++)
+                SET_FOREACH(target, u->meta.dependencies[deps[k]], i)
+                        if ((r = unit_add_default_target_dependency(u, target)) < 0)
+                                return r;
 
         return 0;
 }

commit d4a7e06dea271fb38bfbca0090654f54cfb37992
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Mar 8 03:08:15 2011 +0100

    mount: support less cumbersome x-systemd-xxx mount options

diff --git a/src/mount.c b/src/mount.c
index 8a9ab16..0078010 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -289,9 +289,13 @@ static int mount_add_target_links(Mount *m) {
 
         noauto = !!mount_test_option(p->options, MNTOPT_NOAUTO);
         nofail = !!mount_test_option(p->options, "nofail");
-        handle = !!mount_test_option(p->options, "comment=systemd.mount") ||
+        handle =
+                mount_test_option(p->options, "comment=systemd.mount") ||
+                mount_test_option(p->options, "x-systemd-mount") ||
                 m->meta.manager->mount_auto;
-        automount = !!mount_test_option(p->options, "comment=systemd.automount");
+        automount =
+                mount_test_option(p->options, "comment=systemd.automount") ||
+                mount_test_option(p->options, "x-systemd-automount");
 
         if (mount_test_option(p->options, "_netdev") ||
             (p->fstype && fstype_is_network(p->fstype))) {

commit 267632f0ab26bbcec6bc93682cf43d0f983c41d8
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Mar 8 03:04:47 2011 +0100

    unit: distuingish mandatory from triggering conditions

diff --git a/TODO b/TODO
index 0a2f761..cad9774 100644
--- a/TODO
+++ b/TODO
@@ -14,8 +14,6 @@ F15:
 
 * hook emergency.target into local-fs.target in some way as OnFailure with isolate
 
-* introduce simple way to do mandatory conditions (make current conditions mandatory, and introduce =| as non-mandatory conditions)
-
 * mount /dev/.run and /var/run as bind mounts
 
 * Make use of UnknownInterface, UnknownObject
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
index fa8821a..54903fb 100644
--- a/man/systemd.unit.xml
+++ b/man/systemd.unit.xml
@@ -622,8 +622,8 @@
                                 environment and optionally test
                                 whether it is a specific
                                 implementation. Takes either boolean
-                                value to check if being executed in any
-                                virtual environment or one of the
+                                value to check if being executed in
+                                any virtual environment or one of the
                                 <varname>qemu</varname>,
                                 <varname>kvm</varname>,
                                 <varname>vmware</varname>,
@@ -642,9 +642,20 @@
                                 will always fail, otherwise
                                 succeed. If multiple conditions are
                                 specified the unit will be executed if
-                                at least one of them applies (i.e. a
-                                logical OR is
-                                applied).</para></listitem>
+                                all of them apply (i.e. a logical AND
+                                is applied). Condition checks can be
+                                prefixed with a pipe symbol (|) in
+                                which case a condition becomes a
+                                triggering condition. If at least one
+                                triggering condition is defined for a
+                                unit then the unit will be executed if
+                                at least one of the triggering
+                                conditions apply and all of the
+                                non-triggering conditions. If you
+                                prefix an argument with the pipe
+                                symbol and an exclamation mark the
+                                pipe symbol must be passed first, the
+                                exclamation second.</para></listitem>
                         </varlistentry>
                 </variablelist>
 
diff --git a/src/condition.c b/src/condition.c
index 630350e..1d6cf12 100644
--- a/src/condition.c
+++ b/src/condition.c
@@ -27,11 +27,12 @@
 #include "util.h"
 #include "condition.h"
 
-Condition* condition_new(ConditionType type, const char *parameter, bool negate) {
+Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate) {
         Condition *c;
 
         c = new0(Condition, 1);
         c->type = type;
+        c->trigger = trigger;
         c->negate = negate;
 
         if (parameter)
@@ -153,17 +154,28 @@ bool condition_test(Condition *c) {
 
 bool condition_test_list(Condition *first) {
         Condition *c;
+        int triggered = -1;
 
         /* If the condition list is empty, then it is true */
         if (!first)
                 return true;
 
-        /* Otherwise, if any of the conditions apply we return true */
-        LIST_FOREACH(conditions, c, first)
-                if (condition_test(c))
-                        return true;
+        /* Otherwise, if all of the non-trigger conditions apply and
+         * if any of the trigger conditions apply (unless there are
+         * none) we return true */
+        LIST_FOREACH(conditions, c, first) {
+                bool b;
+
+                b = condition_test(c);
+
+                if (!c->trigger && !b)
+                        return false;
+
+                if (c->trigger && triggered <= 0)
+                        triggered = b;
+        }
 
-        return false;
+        return triggered != 0;
 }
 
 void condition_dump(Condition *c, FILE *f, const char *prefix) {
@@ -174,9 +186,10 @@ void condition_dump(Condition *c, FILE *f, const char *prefix) {
                 prefix = "";
 
         fprintf(f,
-                "%s%s: %s%s\n",
+                "%s%s: %s%s%s\n",
                 prefix,
                 condition_type_to_string(c->type),
+                c->trigger ? "|" : "",
                 c->negate ? "!" : "",
                 c->parameter);
 }
diff --git a/src/condition.h b/src/condition.h
index f4903d7..0ce713b 100644
--- a/src/condition.h
+++ b/src/condition.h
@@ -39,12 +39,14 @@ typedef enum ConditionType {
 typedef struct Condition {
         ConditionType type;
         char *parameter;
-        bool negate;
+
+        bool trigger:1;
+        bool negate:1;
 
         LIST_FIELDS(struct Condition, conditions);
 } Condition;
 
-Condition* condition_new(ConditionType type, const char *parameter, bool negate);
+Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate);
 void condition_free(Condition *c);
 void condition_free_list(Condition *c);
 
diff --git a/src/load-fragment.c b/src/load-fragment.c
index bd7529f..334bc71 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -1397,7 +1397,7 @@ static int config_parse_condition_path(
                 void *userdata) {
 
         Unit *u = data;
-        bool negate;
+        bool trigger, negate;
         Condition *c;
 
         assert(filename);
@@ -1405,6 +1405,9 @@ static int config_parse_condition_path(
         assert(rvalue);
         assert(data);
 
+        if ((trigger = rvalue[0] == '|'))
+                rvalue++;
+
         if ((negate = rvalue[0] == '!'))
                 rvalue++;
 
@@ -1414,7 +1417,7 @@ static int config_parse_condition_path(
         }
 
         if (!(c = condition_new(streq(lvalue, "ConditionPathExists") ? CONDITION_PATH_EXISTS : CONDITION_DIRECTORY_NOT_EMPTY,
-                                rvalue, negate)))
+                                rvalue, trigger, negate)))
                 return -ENOMEM;
 
         LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
@@ -1431,7 +1434,7 @@ static int config_parse_condition_kernel(
                 void *userdata) {
 
         Unit *u = data;
-        bool negate;
+        bool trigger, negate;
         Condition *c;
 
         assert(filename);
@@ -1439,10 +1442,13 @@ static int config_parse_condition_kernel(
         assert(rvalue);
         assert(data);
 
+        if ((trigger = rvalue[0] == '|'))
+                rvalue++;
+
         if ((negate = rvalue[0] == '!'))
                 rvalue++;
 
-        if (!(c = condition_new(CONDITION_KERNEL_COMMAND_LINE, rvalue, negate)))
+        if (!(c = condition_new(CONDITION_KERNEL_COMMAND_LINE, rvalue, trigger, negate)))
                 return -ENOMEM;
 
         LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
@@ -1459,7 +1465,7 @@ static int config_parse_condition_virt(
                 void *userdata) {
 
         Unit *u = data;
-        bool negate;
+        bool trigger, negate;
         Condition *c;
 
         assert(filename);
@@ -1467,10 +1473,13 @@ static int config_parse_condition_virt(
         assert(rvalue);
         assert(data);
 
+        if ((trigger = rvalue[0] == '|'))
+                rvalue++;
+
         if ((negate = rvalue[0] == '!'))
                 rvalue++;
 
-        if (!(c = condition_new(CONDITION_VIRTUALIZATION, rvalue, negate)))
+        if (!(c = condition_new(CONDITION_VIRTUALIZATION, rvalue, trigger, negate)))
                 return -ENOMEM;
 
         LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
@@ -1488,7 +1497,7 @@ static int config_parse_condition_null(
 
         Unit *u = data;
         Condition *c;
-        bool negate;
+        bool trigger, negate;
         int b;
 
         assert(filename);
@@ -1496,6 +1505,9 @@ static int config_parse_condition_null(
         assert(rvalue);
         assert(data);
 
+        if ((trigger = rvalue[0] == '|'))
+                rvalue++;
+
         if ((negate = rvalue[0] == '!'))
                 rvalue++;
 
@@ -1507,7 +1519,7 @@ static int config_parse_condition_null(
         if (!b)
                 negate = !negate;
 
-        if (!(c = condition_new(CONDITION_NULL, NULL, negate)))
+        if (!(c = condition_new(CONDITION_NULL, NULL, trigger, negate)))
                 return -ENOMEM;
 
         LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
diff --git a/units/systemd-sysctl.service.in b/units/systemd-sysctl.service.in
index ada4478..ea78230 100644
--- a/units/systemd-sysctl.service.in
+++ b/units/systemd-sysctl.service.in
@@ -11,8 +11,8 @@ DefaultDependencies=no
 Conflicts=shutdown.target
 After=systemd-readahead-collect.service systemd-readahead-replay.service
 Before=sysinit.target shutdown.target
-ConditionPathExists=/etc/sysctl.conf
-ConditionDirectoryNotEmpty=/etc/sysctl.d
+ConditionPathExists=|/etc/sysctl.conf
+ConditionDirectoryNotEmpty=|/etc/sysctl.d
 
 [Service]
 Type=oneshot

commit 08672cb5071af320127f6fe8d0916f62bedd82f3
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Mar 8 02:27:43 2011 +0100

    dbus: return DBUS_ERROR_UNKNOWN_OBJECT when an object is unknown

diff --git a/src/dbus-job.c b/src/dbus-job.c
index 2a33039..e90d585 100644
--- a/src/dbus-job.c
+++ b/src/dbus-job.c
@@ -193,8 +193,11 @@ static DBusHandlerResult bus_job_message_handler(DBusConnection *connection, DBu
                 if (r == -ENOMEM)
                         return DBUS_HANDLER_RESULT_NEED_MEMORY;
 
-                if (r == -ENOENT)
-                        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+                if (r == -ENOENT) {
+                        DBusError e;
+                        dbus_set_error_const(&e, DBUS_ERROR_UNKNOWN_OBJECT, "Unknown job");
+                        return bus_send_error_reply(m, connection, message, &e, r);
+                }
 
                 return bus_send_error_reply(m, connection, message, NULL, r);
         }
diff --git a/src/dbus-unit.c b/src/dbus-unit.c
index 835eeda..cd6ad84 100644
--- a/src/dbus-unit.c
+++ b/src/dbus-unit.c
@@ -567,8 +567,11 @@ static DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, DB
                 if (r == -ENOMEM)
                         return DBUS_HANDLER_RESULT_NEED_MEMORY;
 
-                if (r == -ENOENT)
-                        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+                if (r == -ENOENT) {
+                        DBusError e;
+                        dbus_set_error_const(&e, DBUS_ERROR_UNKNOWN_OBJECT, "Unknown unit");
+                        return bus_send_error_reply(m, connection, message, &e, r);
+                }
 
                 return bus_send_error_reply(m, connection, message, NULL, r);
         }
diff --git a/src/dbus.h b/src/dbus.h
index 255b653..2aaeb47 100644
--- a/src/dbus.h
+++ b/src/dbus.h
@@ -24,6 +24,14 @@
 
 #include <dbus/dbus.h>
 
+#ifndef DBUS_ERROR_UNKNOWN_OBJECT
+#define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
+#endif
+
+#ifndef DBUS_ERROR_UNKNOWN_INTERFACE
+#define DBUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface"
+#endif
+
 #include "manager.h"
 
 typedef int (*BusPropertyCallback)(Manager *m, DBusMessageIter *iter, const char *property, void *data);



More information about the systemd-commits mailing list