diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-02-21 22:07:55 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-02-21 22:07:55 +0100 |
commit | 039655a40c77f88e4f9ccc00824f2f483f22f2c1 (patch) | |
tree | d471f7478acb0e2134c9ecbe5b06102492120828 /src/condition.c | |
parent | 07faed4f99d0c798f92de3032b9c20ca31388494 (diff) |
unit: introduce ConditionVirtualization=
Diffstat (limited to 'src/condition.c')
-rw-r--r-- | src/condition.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/condition.c b/src/condition.c index 21da2eb9e9..3ab4d4e225 100644 --- a/src/condition.c +++ b/src/condition.c @@ -64,6 +64,8 @@ static bool test_kernel_command_line(const char *parameter) { size_t l, pl; bool found = false; + assert(parameter); + if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) { log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); return false; @@ -98,6 +100,28 @@ static bool test_kernel_command_line(const char *parameter) { return found; } +static bool test_virtualization(const char *parameter) { + int r, b; + const char *id; + + assert(parameter); + + if ((r = detect_virtualization(&id)) < 0) { + log_warning("Failed to detect virtualization, ignoring: %s", strerror(-r)); + return false; + } + + b = parse_boolean(parameter); + + if (r > 0 && b > 0) + return true; + + if (r == 0 && b == 0) + return true; + + return streq(parameter, id); +} + bool condition_test(Condition *c) { assert(c); @@ -116,6 +140,9 @@ bool condition_test(Condition *c) { case CONDITION_KERNEL_COMMAND_LINE: return !!test_kernel_command_line(c->parameter) == !c->negate; + case CONDITION_VIRTUALIZATION: + return !!test_virtualization(c->parameter) == !c->negate; + case CONDITION_NULL: return !c->negate; |