summaryrefslogtreecommitdiff
path: root/src/core/condition.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-06-25 16:09:07 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-07-17 23:41:10 -0400
commit52990c2e0eabd1c11280f553f858062d4165b92f (patch)
tree68a522509cc2b3aa8c89835459bf618e3b7a6d74 /src/core/condition.c
parent4b744dfabebd10bf0f13b64060f44b1bd6c82704 (diff)
systemd,systemctl: export condition status and show failing condition
$ systemctl --user status hoohoo hoohoo.service Loaded: loaded (/home/zbyszek/.config/systemd/user/hoohoo.service; static) Active: inactive (dead) start condition failed at Tue 2013-06-25 18:08:42 EDT; 1s ago ConditionPathExists=/tmp/hoo was not met Full information is exported over D-Bus: [(condition, trigger, negate, param, state),...] where state is one of "failed" (<0), "untested" (0), "OK" (>0). I've decided to use 0 for "untested", because it might be useful to differentiate different types of failure later on, without breaking compatibility. systemctl shows the failing condition, if there was a non-trigger failing condition, or says "none of the trigger conditions were met", because there're often many trigger conditions, and they must all fail for the condition to fail, so printing them all would consume a lot of space, and bring unnecessary attention to something that is quite low-level.
Diffstat (limited to 'src/core/condition.c')
-rw-r--r--src/core/condition.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/core/condition.c b/src/core/condition.c
index 2fbc5ad0e6..6c387450af 100644
--- a/src/core/condition.c
+++ b/src/core/condition.c
@@ -250,7 +250,7 @@ static bool test_ac_power(const char *parameter) {
return (on_ac_power() != 0) == !!r;
}
-bool condition_test(Condition *c) {
+static bool condition_test(Condition *c) {
assert(c);
switch(c->type) {
@@ -358,6 +358,7 @@ bool condition_test_list(const char *unit, Condition *first) {
c->parameter,
b ? "succeeded" : "failed",
unit);
+ c->state = b ? 1 : -1;
if (!c->trigger && !b)
return false;
@@ -377,12 +378,13 @@ void condition_dump(Condition *c, FILE *f, const char *prefix) {
prefix = "";
fprintf(f,
- "%s\t%s: %s%s%s\n",
+ "%s\t%s: %s%s%s %s\n",
prefix,
condition_type_to_string(c->type),
c->trigger ? "|" : "",
c->negate ? "!" : "",
- c->parameter);
+ c->parameter,
+ c->state < 0 ? "failed" : c->state > 0 ? "succeeded" : "untested");
}
void condition_dump_list(Condition *first, FILE *f, const char *prefix) {