chiark / gitweb /
unit: introduce ConditionPathIsMountPoint=
authorLennart Poettering <lennart@poettering.net>
Tue, 20 Sep 2011 22:44:51 +0000 (00:44 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Sep 2011 22:50:40 +0000 (00:50 +0200)
TODO
man/systemd.unit.xml
src/condition.c
src/condition.h
src/load-fragment-gperf.gperf.m4
src/load-fragment.c

diff --git a/TODO b/TODO
index fd3a5f6..fcd76cb 100644 (file)
--- a/TODO
+++ b/TODO
@@ -13,6 +13,8 @@ Bugfixes:
 
 Features:
 
+* introduce sd_log_open() to create a connection to the syslog bridge via sd-daemon.h
+
 * when a bus name of a service disappears from the bus make sure to queue further activation requests
 
 * something like ConditionExec= or ExecStartPre= without failure state
index a94476a..4e2590d 100644 (file)
                                 <term><varname>ConditionPathExists=</varname></term>
                                 <term><varname>ConditionPathExistsGlob=</varname></term>
                                 <term><varname>ConditionPathIsDirectory=</varname></term>
+                                <term><varname>ConditionPathIsMountPoint=</varname></term>
                                 <term><varname>ConditionDirectoryNotEmpty=</varname></term>
                                 <term><varname>ConditionFileIsExecutable=</varname></term>
                                 <term><varname>ConditionKernelCommandLine=</varname></term>
                                 works in a similar way, but checks for
                                 the existence of at least one file or
                                 directory matching the specified
-                                globbing pattern.
-                                <varname>ConditionPathIsDirectory=</varname>
-                                is similar to <varname>ConditionPathExists=</varname>
-                                but verifies whether a certain path exists and
-                                is a directory. It does not follow symlinks.
-                                <varname>ConditionFileIsExecutable=</varname>
-                                is similar to <varname>ConditionPathExists=</varname>
-                                but verifies whether a certain path exists,
-                                is a regular file and marked executable.
-                                It follows symlinks.
+                                globbing
+                                pattern. <varname>ConditionPathIsDirectory=</varname>
+                                is similar to
+                                <varname>ConditionPathExists=</varname>
+                                but verifies whether a certain path
+                                exists and is a directory. It does not
+                                follow
+                                symlinks. <varname>ConditionPathIsMountPoint=</varname>
+                                is similar to
+                                <varname>ConditionPathExists=</varname>
+                                but verifies whether a certain path
+                                exists and is a mount
+                                point. <varname>ConditionFileIsExecutable=</varname>
+                                is similar to
+                                <varname>ConditionPathExists=</varname>
+                                but verifies whether a certain path
+                                exists, is a regular file and marked
+                                executable. It follows symlinks.
                                 <varname>ConditionDirectoryNotEmpty=</varname>
                                 is similar to
                                 <varname>ConditionPathExists=</varname>
index 933aec8..131b456 100644 (file)
@@ -36,18 +36,21 @@ Condition* condition_new(ConditionType type, const char *parameter, bool trigger
 
         assert(type < _CONDITION_TYPE_MAX);
 
-        if (!(c = new0(Condition, 1)))
+        c = new0(Condition, 1);
+        if (!c)
                 return NULL;
 
         c->type = type;
         c->trigger = trigger;
         c->negate = negate;
 
-        if (parameter)
-                if (!(c->parameter = strdup(parameter))) {
+        if (parameter) {
+                c->parameter = strdup(parameter);
+                if (!c->parameter) {
                         free(c);
                         return NULL;
                 }
+        }
 
         return c;
 }
@@ -78,7 +81,8 @@ static bool test_kernel_command_line(const char *parameter) {
         if (detect_container(NULL) > 0)
                 return false;
 
-        if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) {
+        r = read_one_line_file("/proc/cmdline", &line);
+        if (r < 0) {
                 log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
                 return false;
         }
@@ -89,7 +93,8 @@ static bool test_kernel_command_line(const char *parameter) {
         FOREACH_WORD_QUOTED(w, l, line, state) {
 
                 free(word);
-                if (!(word = strndup(w, l)))
+                word = strndup(w, l);
+                if (!word)
                         break;
 
                 if (equal) {
@@ -118,7 +123,8 @@ static bool test_virtualization(const char *parameter) {
 
         assert(parameter);
 
-        if ((r = detect_virtualization(&id)) < 0) {
+        r = detect_virtualization(&id);
+        if (r < 0) {
                 log_warning("Failed to detect virtualization, ignoring: %s", strerror(-r));
                 return false;
         }
@@ -161,6 +167,9 @@ bool condition_test(Condition *c) {
                 return S_ISDIR(st.st_mode) == !c->negate;
         }
 
+        case CONDITION_PATH_IS_MOUNT_POINT:
+                return (path_is_mount_point(c->parameter, true) > 0) == !c->negate;
+
         case CONDITION_DIRECTORY_NOT_EMPTY: {
                 int k;
 
@@ -247,6 +256,7 @@ static const char* const condition_type_table[_CONDITION_TYPE_MAX] = {
         [CONDITION_PATH_EXISTS] = "ConditionPathExists",
         [CONDITION_PATH_EXISTS_GLOB] = "ConditionPathExistsGlob",
         [CONDITION_PATH_IS_DIRECTORY] = "ConditionPathIsDirectory",
+        [CONDITION_PATH_IS_MOUNT_POINT] = "ConditionPathIsMountPoint",
         [CONDITION_DIRECTORY_NOT_EMPTY] = "ConditionDirectoryNotEmpty",
         [CONDITION_KERNEL_COMMAND_LINE] = "ConditionKernelCommandLine",
         [CONDITION_VIRTUALIZATION] = "ConditionVirtualization",
index 672996e..66b020f 100644 (file)
@@ -30,6 +30,7 @@ typedef enum ConditionType {
         CONDITION_PATH_EXISTS,
         CONDITION_PATH_EXISTS_GLOB,
         CONDITION_PATH_IS_DIRECTORY,
+        CONDITION_PATH_IS_MOUNT_POINT,
         CONDITION_DIRECTORY_NOT_EMPTY,
         CONDITION_FILE_IS_EXECUTABLE,
         CONDITION_KERNEL_COMMAND_LINE,
index 08223c5..370a7a7 100644 (file)
@@ -112,6 +112,7 @@ Unit.JobTimeoutSec,              config_parse_usec,                  0,
 Unit.ConditionPathExists,        config_parse_unit_condition_path,   CONDITION_PATH_EXISTS,         0
 Unit.ConditionPathExistsGlob,    config_parse_unit_condition_path,   CONDITION_PATH_EXISTS_GLOB,    0
 Unit.ConditionPathIsDirectory,   config_parse_unit_condition_path,   CONDITION_PATH_IS_DIRECTORY,   0
+Unit.ConditionPathIsMountPoint,  config_parse_unit_condition_path,   CONDITION_PATH_IS_MOUNT_POINT, 0
 Unit.ConditionDirectoryNotEmpty, config_parse_unit_condition_path,   CONDITION_DIRECTORY_NOT_EMPTY, 0
 Unit.ConditionFileIsExecutable,  config_parse_unit_condition_path,   CONDITION_FILE_IS_EXECUTABLE,  0
 Unit.ConditionKernelCommandLine, config_parse_unit_condition_string, CONDITION_KERNEL_COMMAND_LINE, 0
index c8b4b5a..c7d2da3 100644 (file)
@@ -1545,10 +1545,12 @@ int config_parse_unit_condition_path(
         assert(rvalue);
         assert(data);
 
-        if ((trigger = rvalue[0] == '|'))
+        trigger = rvalue[0] == '|';
+        if (trigger)
                 rvalue++;
 
-        if ((negate = rvalue[0] == '!'))
+        negate = rvalue[0] == '!';
+        if (negate)
                 rvalue++;
 
         if (!path_is_absolute(rvalue)) {
@@ -1556,7 +1558,8 @@ int config_parse_unit_condition_path(
                 return 0;
         }
 
-        if (!(c = condition_new(cond, rvalue, trigger, negate)))
+        c = condition_new(cond, rvalue, trigger, negate);
+        if (!c)
                 return -ENOMEM;
 
         LIST_PREPEND(Condition, conditions, u->meta.conditions, c);