<varlistentry>
<term><varname>ConditionPathExists=</varname></term>
+ <term><varname>ConditionDirectoryNotEmpty=</varname></term>
<term><varname>ConditionKernelCommandLine=</varname></term>
<term><varname>ConditionNull=</varname></term>
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
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;
typedef enum ConditionType {
CONDITION_PATH_EXISTS,
+ CONDITION_DIRECTORY_NOT_EMPTY,
CONDITION_KERNEL_COMMAND_LINE,
CONDITION_NULL,
_CONDITION_TYPE_MAX,
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);
{ "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" },
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;