summaryrefslogtreecommitdiff
path: root/src
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 /src
parent418112a296e898cbd7fe8585995ae60936368327 (diff)
unit: introduce ConditionPathIsMountPoint=
Diffstat (limited to 'src')
-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
4 files changed, 24 insertions, 9 deletions
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);