From ab7f148f81723ef18402b78ea34fb5e1bbe85ff0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 21 Sep 2011 00:44:51 +0200 Subject: [PATCH] unit: introduce ConditionPathIsMountPoint= --- TODO | 2 ++ man/systemd.unit.xml | 29 +++++++++++++++++++---------- src/condition.c | 22 ++++++++++++++++------ src/condition.h | 1 + src/load-fragment-gperf.gperf.m4 | 1 + src/load-fragment.c | 9 ++++++--- 6 files changed, 45 insertions(+), 19 deletions(-) diff --git a/TODO b/TODO index fd3a5f6a..fcd76cb0 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 a94476ac..4e2590d0 100644 --- a/man/systemd.unit.xml +++ b/man/systemd.unit.xml @@ -665,6 +665,7 @@ ConditionPathExists= ConditionPathExistsGlob= ConditionPathIsDirectory= + ConditionPathIsMountPoint= ConditionDirectoryNotEmpty= ConditionFileIsExecutable= ConditionKernelCommandLine= @@ -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. - ConditionPathIsDirectory= - is similar to ConditionPathExists= - but verifies whether a certain path exists and - is a directory. It does not follow symlinks. - ConditionFileIsExecutable= - is similar to ConditionPathExists= - but verifies whether a certain path exists, - is a regular file and marked executable. - It follows symlinks. + globbing + pattern. ConditionPathIsDirectory= + is similar to + ConditionPathExists= + but verifies whether a certain path + exists and is a directory. It does not + follow + symlinks. ConditionPathIsMountPoint= + is similar to + ConditionPathExists= + but verifies whether a certain path + exists and is a mount + point. ConditionFileIsExecutable= + is similar to + ConditionPathExists= + but verifies whether a certain path + exists, is a regular file and marked + executable. It follows symlinks. ConditionDirectoryNotEmpty= is similar to ConditionPathExists= diff --git a/src/condition.c b/src/condition.c index 933aec84..131b4568 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 672996e8..66b020fc 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 08223c5c..370a7a7e 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 c8b4b5a9..c7d2da34 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); -- 2.39.5