X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Fcondition.c;h=630350ed365ea818b4ac0806bfb3cb8940322746;hb=83310f162d2a78913b2748aaa5ffb1ae8226484f;hp=21da2eb9e94c032778064b3283904ba1532ad5cf;hpb=36af55d99711e9accdf42d8a7df60e069f4086c0;p=elogind.git diff --git a/src/condition.c b/src/condition.c index 21da2eb9e..630350ed3 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); @@ -114,7 +138,10 @@ bool condition_test(Condition *c) { } case CONDITION_KERNEL_COMMAND_LINE: - return !!test_kernel_command_line(c->parameter) == !c->negate; + 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;