summaryrefslogtreecommitdiff
path: root/src/shared/condition.c
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2016-10-27 13:16:16 +0300
committerGitHub <noreply@github.com>2016-10-27 13:16:16 +0300
commit492466c1b5fd8c168cb2a09b9330019f60074195 (patch)
tree389e0179ae350737bee0b0623543175c008d6d63 /src/shared/condition.c
parent342d3ac165680197efe7973efbe08f7eb12b6b11 (diff)
parent4bb30aeaf8e756b20d66e13af2eac0c5a30b01fa (diff)
Merge pull request #4442 from keszybz/detect-virt-userns
detect-virt: add --private-users switch to check if a userns is active; add Condition=private-users
Diffstat (limited to 'src/shared/condition.c')
-rw-r--r--src/shared/condition.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/shared/condition.c b/src/shared/condition.c
index 69b4837e1f..8bd6a51a99 100644
--- a/src/shared/condition.c
+++ b/src/shared/condition.c
@@ -146,25 +146,24 @@ static int condition_test_virtualization(Condition *c) {
assert(c->parameter);
assert(c->type == CONDITION_VIRTUALIZATION);
+ if (streq(c->parameter, "private-users"))
+ return running_in_userns();
+
v = detect_virtualization();
if (v < 0)
return v;
/* First, compare with yes/no */
b = parse_boolean(c->parameter);
-
- if (v > 0 && b > 0)
- return true;
-
- if (v == 0 && b == 0)
- return true;
+ if (b >= 0)
+ return b == !!v;
/* Then, compare categorization */
- if (VIRTUALIZATION_IS_VM(v) && streq(c->parameter, "vm"))
- return true;
+ if (streq(c->parameter, "vm"))
+ return VIRTUALIZATION_IS_VM(v);
- if (VIRTUALIZATION_IS_CONTAINER(v) && streq(c->parameter, "container"))
- return true;
+ if (streq(c->parameter, "container"))
+ return VIRTUALIZATION_IS_CONTAINER(v);
/* Finally compare id */
return v != VIRTUALIZATION_NONE && streq(c->parameter, virtualization_to_string(v));