summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-09-21 00:44:51 +0200
committerLennart Poettering <lennart@poettering.net>2011-09-21 00:50:40 +0200
commitab7f148f81723ef18402b78ea34fb5e1bbe85ff0 (patch)
tree17abf5deacc32bdcbb55843e0e02f179e0c6fa84
parent418112a296e898cbd7fe8585995ae60936368327 (diff)
unit: introduce ConditionPathIsMountPoint=
-rw-r--r--TODO2
-rw-r--r--man/systemd.unit.xml29
-rw-r--r--src/condition.c22
-rw-r--r--src/condition.h1
-rw-r--r--src/load-fragment-gperf.gperf.m41
-rw-r--r--src/load-fragment.c9
6 files changed, 45 insertions, 19 deletions
diff --git a/TODO b/TODO
index fd3a5f6ac7..fcd76cb06b 100644
--- 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
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
index a94476acb8..4e2590d006 100644
--- a/man/systemd.unit.xml
+++ b/man/systemd.unit.xml
@@ -665,6 +665,7 @@
<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>
@@ -695,16 +696,24 @@
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>
diff --git a/src/condition.c b/src/condition.c
index 933aec8485..131b456806 100644
--- a/src/condition.c
+++ b/src/condition.c
@@ -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",
diff --git a/src/condition.h b/src/condition.h
index 672996e836..66b020fc8c 100644
--- a/src/condition.h
+++ b/src/condition.h
@@ -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,
diff --git a/src/load-fragment-gperf.gperf.m4 b/src/load-fragment-gperf.gperf.m4
index 08223c5c1b..370a7a7eb6 100644
--- a/src/load-fragment-gperf.gperf.m4
+++ b/src/load-fragment-gperf.gperf.m4
@@ -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
diff --git a/src/load-fragment.c b/src/load-fragment.c
index c8b4b5a9c6..c7d2da34b4 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -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);