X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcondition.c;h=21da2eb9e94c032778064b3283904ba1532ad5cf;hb=8e1bd70d4ce6d3881c1df6a6482643a2b3a69bb1;hp=1e69b610ff3e1b2cebffd18b56e6b84605442f3b;hpb=f23c09b0fdec4a421cc002a38621e5be05ed770b;p=elogind.git diff --git a/src/condition.c b/src/condition.c index 1e69b610f..21da2eb9e 100644 --- a/src/condition.c +++ b/src/condition.c @@ -34,10 +34,11 @@ Condition* condition_new(ConditionType type, const char *parameter, bool negate) c->type = type; c->negate = negate; - if (!(c->parameter = strdup(parameter))) { - free(c); - return NULL; - } + if (parameter) + if (!(c->parameter = strdup(parameter))) { + free(c); + return NULL; + } return c; } @@ -105,9 +106,19 @@ 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; + case CONDITION_NULL: + return !c->negate; + default: assert_not_reached("Invalid condition type."); } @@ -152,7 +163,8 @@ void condition_dump_list(Condition *first, FILE *f, const char *prefix) { static const char* const condition_type_table[_CONDITION_TYPE_MAX] = { [CONDITION_KERNEL_COMMAND_LINE] = "ConditionKernelCommandLine", - [CONDITION_PATH_EXISTS] = "ConditionPathExists" + [CONDITION_PATH_EXISTS] = "ConditionPathExists", + [CONDITION_NULL] = "ConditionNull" }; DEFINE_STRING_TABLE_LOOKUP(condition_type, ConditionType);