diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-02-21 02:06:04 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-02-21 02:43:14 +0100 |
commit | 099524d7b0df690e3361ffc3fe3c6aed0558b4fc (patch) | |
tree | 9983d7ff3452ce44a2a8150e124d01e998f8dbd9 /src/shared/condition-util.c | |
parent | a03c5fd2d86c4e3f758a5ca0d98638e5c8bd8d8d (diff) |
core: add new ConditionArchitecture() that checks the architecture returned by uname()'s machine field.
Diffstat (limited to 'src/shared/condition-util.c')
-rw-r--r-- | src/shared/condition-util.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/shared/condition-util.c b/src/shared/condition-util.c index d31c4bf5b1..4aea3caf9d 100644 --- a/src/shared/condition-util.c +++ b/src/shared/condition-util.c @@ -33,6 +33,7 @@ #include "path-util.h" #include "fileio.h" #include "unit.h" +#include "architecture.h" Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate) { Condition *c; @@ -154,6 +155,28 @@ bool condition_test_virtualization(Condition *c) { return (v > 0 && streq(c->parameter, id)) == !c->negate; } +bool condition_test_architecture(Condition *c) { + Architecture a, b; + + assert(c); + assert(c->parameter); + assert(c->type == CONDITION_ARCHITECTURE); + + a = uname_architecture(); + if (a < 0) + return c->negate; + + if (streq(c->parameter, "native")) + b = native_architecture(); + else + b = architecture_from_string(c->parameter); + + if (b < 0) + return c->negate; + + return (a == b) == !c->negate; +} + bool condition_test_host(Condition *c) { sd_id128_t x, y; char *h; @@ -170,7 +193,7 @@ bool condition_test_host(Condition *c) { if (r < 0) return c->negate; - return sd_id128_equal(x, y); + return sd_id128_equal(x, y) == !c->negate; } h = gethostname_malloc(); @@ -237,6 +260,7 @@ static const char* const condition_type_table[_CONDITION_TYPE_MAX] = { [CONDITION_CAPABILITY] = "ConditionCapability", [CONDITION_HOST] = "ConditionHost", [CONDITION_AC_POWER] = "ConditionACPower", + [CONDITION_ARCHITECTURE] = "ConditionArchitecture", [CONDITION_NULL] = "ConditionNull" }; |