[systemd-devel] [PATCH] Log failing start conditions
harald at redhat.com
harald at redhat.com
Wed Jun 26 06:06:38 PDT 2013
From: Harald Hoyer <harald at redhat.com>
$ systemctl status dracut-initqueue.service
dracut-initqueue.service - dracut initqueue hook
Loaded: loaded (/usr/lib/systemd/system/dracut-initqueue.service;
static)
Active: inactive (dead)
start condition failed at Wed 2013-06-26 13:01:05 UTC; 22s ago
Docs: man:dracut-initqueue.service(8)
Jun 26 13:01:05 lenovo systemd[1]: Starting of dracut-initqueue.service
skipped because the following start conditions were not met:
ConditionKernelCommandLine:|rd.break=initqueue
ConditionPathExistsGlob: |/lib/dracut/hooks/initqueue/timeout/*.sh
ConditionPathExistsGlob: |/lib/dracut/hooks/initqueue/online/*.sh
ConditionPathExistsGlob: |/lib/dracut/hooks/initqueue/finished/*.sh
ConditionPathExistsGlob: |/lib/dracut/hooks/initqueue/settled/*.sh
ConditionPathExistsGlob: |/lib/dracut/hooks/initqueue/*.sh
ConditionPathExists: |/lib/dracut/need-initqueue
Jun 26 13:01:05 lenovo systemd[1]: Started dracut initqueue hook.
---
catalog/systemd.catalog | 9 +++++++++
src/core/condition.c | 33 ++++++++++++++++++++++++++++-----
src/core/condition.h | 5 +++++
src/core/unit.c | 27 ++++++++++++++++++++++++++-
src/systemd/sd-messages.h | 1 +
5 files changed, 69 insertions(+), 6 deletions(-)
diff --git a/catalog/systemd.catalog b/catalog/systemd.catalog
index dbeadb7..e93d414 100644
--- a/catalog/systemd.catalog
+++ b/catalog/systemd.catalog
@@ -193,6 +193,15 @@ Unit @UNIT@ has finished starting up.
The start-up result is @RESULT at .
+-- b144edc73cf3493bb4442c670361eae8
+Subject: Conditions of unit @UNIT@ were not met
+Defined-By: systemd
+Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
+Unit @UNIT@ was not started because some conditions were not met.
+
+The result of the conditions were:
+ at CONDITION_RESULTS@
+
-- de5b426a63be47a7b6ac3eaac82e2f6f
Subject: Unit @UNIT@ has begun shutting down
Defined-By: systemd
diff --git a/src/core/condition.c b/src/core/condition.c
index b2617ef..a8f5b98 100644
--- a/src/core/condition.c
+++ b/src/core/condition.c
@@ -345,15 +345,14 @@ bool condition_test_list(Condition *first) {
* if any of the trigger conditions apply (unless there are
* none) we return true */
LIST_FOREACH(conditions, c, first) {
- bool b;
+ c->result = condition_test(c);
+ c->tested = true;
- b = condition_test(c);
-
- if (!c->trigger && !b)
+ if (!c->trigger && !c->result)
return false;
if (c->trigger && triggered <= 0)
- triggered = b;
+ triggered = c->result;
}
return triggered != 0;
@@ -382,6 +381,30 @@ void condition_dump_list(Condition *first, FILE *f, const char *prefix) {
condition_dump(c, f, prefix);
}
+void condition_dump_result(Condition *c, FILE *f) {
+ assert(c);
+ assert(f);
+
+ if (!c->tested)
+ return;
+ if (c->result)
+ return;
+
+ fprintf(f,
+ "%s: %s%s%s\n",
+ condition_type_to_string(c->type),
+ c->trigger ? "|" : "",
+ c->negate ? "!" : "",
+ c->parameter);
+}
+
+void condition_dump_list_result(Condition *first, FILE *f) {
+ Condition *c;
+
+ LIST_FOREACH(conditions, c, first)
+ condition_dump_result(c, f);
+}
+
static const char* const condition_type_table[_CONDITION_TYPE_MAX] = {
[CONDITION_PATH_EXISTS] = "ConditionPathExists",
[CONDITION_PATH_EXISTS_GLOB] = "ConditionPathExistsGlob",
diff --git a/src/core/condition.h b/src/core/condition.h
index 50ed955..bb7a15a 100644
--- a/src/core/condition.h
+++ b/src/core/condition.h
@@ -52,6 +52,8 @@ typedef struct Condition {
bool trigger:1;
bool negate:1;
+ bool result:1;
+ bool tested:1;
LIST_FIELDS(struct Condition, conditions);
} Condition;
@@ -66,5 +68,8 @@ bool condition_test_list(Condition *c);
void condition_dump(Condition *c, FILE *f, const char *prefix);
void condition_dump_list(Condition *c, FILE *f, const char *prefix);
+void condition_dump_result(Condition *c, FILE *f);
+void condition_dump_list_result(Condition *first, FILE *f);
+
const char* condition_type_to_string(ConditionType t) _const_;
int condition_type_from_string(const char *s) _pure_;
diff --git a/src/core/unit.c b/src/core/unit.c
index f75045d..a9dd613 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -1082,7 +1082,32 @@ int unit_start(Unit *u) {
* but we don't want to recheck the condition in that case. */
if (state != UNIT_ACTIVATING &&
!unit_condition_test(u)) {
- log_debug_unit(u->id, "Starting of %s requested but condition failed. Ignoring.", u->id);
+ _cleanup_free_ char *buf = NULL;
+ FILE *f;
+ size_t size;
+
+ if (!(f = open_memstream(&buf, &size))) {
+ log_warning("Failed to allocate memory stream.");
+ return -EALREADY;
+ }
+
+ condition_dump_list_result(u->conditions, f);
+
+ if (ferror(f)) {
+ fclose(f);
+ log_warning("Failed to write status stream");
+ return -EALREADY;
+ }
+
+ fclose(f);
+
+ log_struct_unit(LOG_NOTICE,
+ u->id,
+ MESSAGE_ID(SD_MESSAGE_UNIT_CONDITIONS),
+ "MESSAGE=Starting of %s skipped because the following start conditions were not met:\n%s", u->id, buf,
+ "CONDITION_RESULTS=%s", buf,
+ NULL);
+
return -EALREADY;
}
diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h
index c811a06..c85dda1 100644
--- a/src/systemd/sd-messages.h
+++ b/src/systemd/sd-messages.h
@@ -62,6 +62,7 @@ extern "C" {
#define SD_MESSAGE_UNIT_STARTING SD_ID128_MAKE(7d,49,58,e8,42,da,4a,75,8f,6c,1c,dc,7b,36,dc,c5)
#define SD_MESSAGE_UNIT_STARTED SD_ID128_MAKE(39,f5,34,79,d3,a0,45,ac,8e,11,78,62,48,23,1f,bf)
+#define SD_MESSAGE_UNIT_CONDITIONS SD_ID128_MAKE(b1,44,ed,c7,3c,f3,49,3b,b4,44,2c,67,03,61,ea,e8)
#define SD_MESSAGE_UNIT_STOPPING SD_ID128_MAKE(de,5b,42,6a,63,be,47,a7,b6,ac,3e,aa,c8,2e,2f,6f)
#define SD_MESSAGE_UNIT_STOPPED SD_ID128_MAKE(9d,1a,aa,27,d6,01,40,bd,96,36,54,38,aa,d2,02,86)
#define SD_MESSAGE_UNIT_FAILED SD_ID128_MAKE(be,02,cf,68,55,d2,42,8b,a4,0d,f7,e9,d0,22,f0,3d)
--
1.8.3.1
More information about the systemd-devel
mailing list