summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/condition.c14
-rw-r--r--src/core/condition.h1
-rw-r--r--src/core/load-fragment-gperf.gperf.m41
3 files changed, 16 insertions, 0 deletions
diff --git a/src/core/condition.c b/src/core/condition.c
index 32a37ccad6..b3184922b8 100644
--- a/src/core/condition.c
+++ b/src/core/condition.c
@@ -221,6 +221,16 @@ static bool test_host(const char *parameter) {
return b;
}
+static bool test_ac_power(const char *parameter) {
+ int r;
+
+ r = parse_boolean(parameter);
+ if (r < 0)
+ return true;
+
+ return (on_ac_power() != 0) == !!r;
+}
+
bool condition_test(Condition *c) {
assert(c);
@@ -294,6 +304,9 @@ bool condition_test(Condition *c) {
case CONDITION_HOST:
return test_host(c->parameter) == !c->negate;
+ case CONDITION_AC_POWER:
+ return test_ac_power(c->parameter) == !c->negate;
+
case CONDITION_NULL:
return !c->negate;
@@ -364,6 +377,7 @@ static const char* const condition_type_table[_CONDITION_TYPE_MAX] = {
[CONDITION_VIRTUALIZATION] = "ConditionVirtualization",
[CONDITION_SECURITY] = "ConditionSecurity",
[CONDITION_HOST] = "ConditionHost",
+ [CONDITION_AC_POWER] = "ConditionACPower",
[CONDITION_NULL] = "ConditionNull"
};
diff --git a/src/core/condition.h b/src/core/condition.h
index 03954e40b3..1797385d26 100644
--- a/src/core/condition.h
+++ b/src/core/condition.h
@@ -40,6 +40,7 @@ typedef enum ConditionType {
CONDITION_SECURITY,
CONDITION_CAPABILITY,
CONDITION_HOST,
+ CONDITION_AC_POWER,
CONDITION_NULL,
_CONDITION_TYPE_MAX,
_CONDITION_TYPE_INVALID = -1
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
index 7212053ca7..7fba0cfb77 100644
--- a/src/core/load-fragment-gperf.gperf.m4
+++ b/src/core/load-fragment-gperf.gperf.m4
@@ -137,6 +137,7 @@ Unit.ConditionVirtualization, config_parse_unit_condition_string, CONDITION_V
Unit.ConditionSecurity, config_parse_unit_condition_string, CONDITION_SECURITY, 0
Unit.ConditionCapability, config_parse_unit_condition_string, CONDITION_CAPABILITY, 0
Unit.ConditionHost, config_parse_unit_condition_string, CONDITION_HOST, 0
+Unit.ConditionACPower, config_parse_unit_condition_string, CONDITION_AC_POWER, 0
Unit.ConditionNull, config_parse_unit_condition_null, 0, 0
m4_dnl
Service.PIDFile, config_parse_unit_path_printf, 0, offsetof(Service, pid_file)