diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-03-08 03:04:47 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-03-08 03:04:47 +0100 |
commit | 267632f0ab26bbcec6bc93682cf43d0f983c41d8 (patch) | |
tree | 32491e0ade93452809938f44283a38e4fca7be63 /src | |
parent | 08672cb5071af320127f6fe8d0916f62bedd82f3 (diff) |
unit: distuingish mandatory from triggering conditions
Diffstat (limited to 'src')
-rw-r--r-- | src/condition.c | 27 | ||||
-rw-r--r-- | src/condition.h | 6 | ||||
-rw-r--r-- | src/load-fragment.c | 28 |
3 files changed, 44 insertions, 17 deletions
diff --git a/src/condition.c b/src/condition.c index 630350ed36..1d6cf12ad4 100644 --- a/src/condition.c +++ b/src/condition.c @@ -27,11 +27,12 @@ #include "util.h" #include "condition.h" -Condition* condition_new(ConditionType type, const char *parameter, bool negate) { +Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate) { Condition *c; c = new0(Condition, 1); c->type = type; + c->trigger = trigger; c->negate = negate; if (parameter) @@ -153,17 +154,28 @@ bool condition_test(Condition *c) { bool condition_test_list(Condition *first) { Condition *c; + int triggered = -1; /* If the condition list is empty, then it is true */ if (!first) return true; - /* Otherwise, if any of the conditions apply we return true */ - LIST_FOREACH(conditions, c, first) - if (condition_test(c)) - return true; + /* Otherwise, if all of the non-trigger conditions apply and + * if any of the trigger conditions apply (unless there are + * none) we return true */ + LIST_FOREACH(conditions, c, first) { + bool b; + + b = condition_test(c); + + if (!c->trigger && !b) + return false; + + if (c->trigger && triggered <= 0) + triggered = b; + } - return false; + return triggered != 0; } void condition_dump(Condition *c, FILE *f, const char *prefix) { @@ -174,9 +186,10 @@ void condition_dump(Condition *c, FILE *f, const char *prefix) { prefix = ""; fprintf(f, - "%s%s: %s%s\n", + "%s%s: %s%s%s\n", prefix, condition_type_to_string(c->type), + c->trigger ? "|" : "", c->negate ? "!" : "", c->parameter); } diff --git a/src/condition.h b/src/condition.h index f4903d76d9..0ce713bc16 100644 --- a/src/condition.h +++ b/src/condition.h @@ -39,12 +39,14 @@ typedef enum ConditionType { typedef struct Condition { ConditionType type; char *parameter; - bool negate; + + bool trigger:1; + bool negate:1; LIST_FIELDS(struct Condition, conditions); } Condition; -Condition* condition_new(ConditionType type, const char *parameter, bool negate); +Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate); void condition_free(Condition *c); void condition_free_list(Condition *c); diff --git a/src/load-fragment.c b/src/load-fragment.c index bd7529ff95..334bc713be 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -1397,7 +1397,7 @@ static int config_parse_condition_path( void *userdata) { Unit *u = data; - bool negate; + bool trigger, negate; Condition *c; assert(filename); @@ -1405,6 +1405,9 @@ static int config_parse_condition_path( assert(rvalue); assert(data); + if ((trigger = rvalue[0] == '|')) + rvalue++; + if ((negate = rvalue[0] == '!')) rvalue++; @@ -1414,7 +1417,7 @@ static int config_parse_condition_path( } if (!(c = condition_new(streq(lvalue, "ConditionPathExists") ? CONDITION_PATH_EXISTS : CONDITION_DIRECTORY_NOT_EMPTY, - rvalue, negate))) + rvalue, trigger, negate))) return -ENOMEM; LIST_PREPEND(Condition, conditions, u->meta.conditions, c); @@ -1431,7 +1434,7 @@ static int config_parse_condition_kernel( void *userdata) { Unit *u = data; - bool negate; + bool trigger, negate; Condition *c; assert(filename); @@ -1439,10 +1442,13 @@ static int config_parse_condition_kernel( assert(rvalue); assert(data); + if ((trigger = rvalue[0] == '|')) + rvalue++; + if ((negate = rvalue[0] == '!')) rvalue++; - if (!(c = condition_new(CONDITION_KERNEL_COMMAND_LINE, rvalue, negate))) + if (!(c = condition_new(CONDITION_KERNEL_COMMAND_LINE, rvalue, trigger, negate))) return -ENOMEM; LIST_PREPEND(Condition, conditions, u->meta.conditions, c); @@ -1459,7 +1465,7 @@ static int config_parse_condition_virt( void *userdata) { Unit *u = data; - bool negate; + bool trigger, negate; Condition *c; assert(filename); @@ -1467,10 +1473,13 @@ static int config_parse_condition_virt( assert(rvalue); assert(data); + if ((trigger = rvalue[0] == '|')) + rvalue++; + if ((negate = rvalue[0] == '!')) rvalue++; - if (!(c = condition_new(CONDITION_VIRTUALIZATION, rvalue, negate))) + if (!(c = condition_new(CONDITION_VIRTUALIZATION, rvalue, trigger, negate))) return -ENOMEM; LIST_PREPEND(Condition, conditions, u->meta.conditions, c); @@ -1488,7 +1497,7 @@ static int config_parse_condition_null( Unit *u = data; Condition *c; - bool negate; + bool trigger, negate; int b; assert(filename); @@ -1496,6 +1505,9 @@ static int config_parse_condition_null( assert(rvalue); assert(data); + if ((trigger = rvalue[0] == '|')) + rvalue++; + if ((negate = rvalue[0] == '!')) rvalue++; @@ -1507,7 +1519,7 @@ static int config_parse_condition_null( if (!b) negate = !negate; - if (!(c = condition_new(CONDITION_NULL, NULL, negate))) + if (!(c = condition_new(CONDITION_NULL, NULL, trigger, negate))) return -ENOMEM; LIST_PREPEND(Condition, conditions, u->meta.conditions, c); |