summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-11-15 20:06:49 +0100
committerLennart Poettering <lennart@poettering.net>2010-11-15 22:13:25 +0100
commit36af55d99711e9accdf42d8a7df60e069f4086c0 (patch)
tree789d2d3d0c8e677be15f142b0c72ffab72e73f3b
parent5c273f855630bf54f6ebe95ea8b45c8abe2ffff6 (diff)
unit: introduce ConditionDirectoryNotEmpty=
-rw-r--r--man/systemd.unit.xml8
-rw-r--r--src/condition.c7
-rw-r--r--src/condition.h1
-rw-r--r--src/load-fragment.c4
-rw-r--r--src/path.c8
5 files changed, 24 insertions, 4 deletions
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
index 39862cf7c8..b29473afa3 100644
--- a/man/systemd.unit.xml
+++ b/man/systemd.unit.xml
@@ -573,6 +573,7 @@
<varlistentry>
<term><varname>ConditionPathExists=</varname></term>
+ <term><varname>ConditionDirectoryNotEmpty=</varname></term>
<term><varname>ConditionKernelCommandLine=</varname></term>
<term><varname>ConditionNull=</varname></term>
@@ -594,7 +595,12 @@
is prefixed with an exclamation mark
(!), the test is negated, and the unit
only started if the path does not
- exist. Similarly
+ exist. <varname>ConditionDirectoryNotEmpty=</varname>
+ is similar to
+ <varname>ConditionPathExists=</varname>
+ but verifies whether a cetrain path is
+ exists and is a non-empty
+ directory. Similarly
<varname>ConditionKernelCommandLine=</varname>
may be used to check whether a
specific kernel command line option is
diff --git a/src/condition.c b/src/condition.c
index 4bbd4dbafa..21da2eb9e9 100644
--- a/src/condition.c
+++ b/src/condition.c
@@ -106,6 +106,13 @@ bool condition_test(Condition *c) {
case CONDITION_PATH_EXISTS:
return (access(c->parameter, F_OK) >= 0) == !c->negate;
+ case CONDITION_DIRECTORY_NOT_EMPTY: {
+ int k;
+
+ k = dir_is_empty(c->parameter);
+ return !(k == -ENOENT || k > 0) == !c->negate;
+ }
+
case CONDITION_KERNEL_COMMAND_LINE:
return !!test_kernel_command_line(c->parameter) == !c->negate;
diff --git a/src/condition.h b/src/condition.h
index b9d3f34aef..2f2689cc6d 100644
--- a/src/condition.h
+++ b/src/condition.h
@@ -28,6 +28,7 @@
typedef enum ConditionType {
CONDITION_PATH_EXISTS,
+ CONDITION_DIRECTORY_NOT_EMPTY,
CONDITION_KERNEL_COMMAND_LINE,
CONDITION_NULL,
_CONDITION_TYPE_MAX,
diff --git a/src/load-fragment.c b/src/load-fragment.c
index 9b39d9161a..1b23205a2f 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -1448,7 +1448,8 @@ static int config_parse_condition_path(
return 0;
}
- if (!(c = condition_new(CONDITION_PATH_EXISTS, rvalue, negate)))
+ if (!(c = condition_new(streq(lvalue, "ConditionPathExists") ? CONDITION_PATH_EXISTS : CONDITION_DIRECTORY_NOT_EMPTY,
+ rvalue, negate)))
return -ENOMEM;
LIST_PREPEND(Condition, conditions, u->meta.conditions, c);
@@ -1815,6 +1816,7 @@ static int load_from_path(Unit *u, const char *path) {
{ "DefaultDependencies", config_parse_bool, &u->meta.default_dependencies, "Unit" },
{ "JobTimeoutSec", config_parse_usec, &u->meta.job_timeout, "Unit" },
{ "ConditionPathExists", config_parse_condition_path, u, "Unit" },
+ { "ConditionDirectoryNotEmpty", config_parse_condition_path, u, "Unit" },
{ "ConditionKernelCommandLine", config_parse_condition_kernel, u, "Unit" },
{ "ConditionNull", config_parse_condition_null, u, "Unit" },
diff --git a/src/path.c b/src/path.c
index f4a0a288bb..a8b1072449 100644
--- a/src/path.c
+++ b/src/path.c
@@ -355,9 +355,13 @@ static void path_enter_waiting(Path *p, bool initial, bool recheck) {
good = access(s->path, F_OK) >= 0;
break;
- case PATH_DIRECTORY_NOT_EMPTY:
- good = dir_is_empty(s->path) == 0;
+ case PATH_DIRECTORY_NOT_EMPTY: {
+ int k;
+
+ k = dir_is_empty(s->path);
+ good = !(k == -ENOENT || k > 0);
break;
+ }
case PATH_CHANGED: {
bool b;