summaryrefslogtreecommitdiff
path: root/src/core/job.c
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2021-08-26 16:44:37 +0100
committerLennart Poettering <lennart@poettering.net>2021-08-28 06:46:37 +0200
commit6e5485617e5f610778055573c31e13769ec801e6 (patch)
treed1fbafd546179755d42b74e9646b1ba6ef553738 /src/core/job.c
parentd52cc0a5318cd33438f7e36f8abd42c5c2dbd4a3 (diff)
downloadsystemd-6e5485617e5f610778055573c31e13769ec801e6.tar.gz
core: Add information on which condition failed to the job done message
When a job is skipped, it's useful to know exactly which condition failed so let's add this information to the error message. To avoid having to dynamically generate a format string, we special case the formatting of condition failed messages.
Diffstat (limited to 'src/core/job.c')
-rw-r--r--src/core/job.c54
1 files changed, 43 insertions, 11 deletions
diff --git a/src/core/job.c b/src/core/job.c
index dd16a0b280..6eb135785b 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -705,19 +705,51 @@ static void job_emit_done_message(Unit *u, uint32_t job_id, JobType t, JobResult
if (!console_only) { /* Skip printing if output goes to the console, and job_print_status_message()
* will actually print something to the console. */
-
+ Condition *c;
const char *mid = job_done_mid(t, result); /* mid may be NULL. log_unit_struct() will ignore it. */
- const char *msg_fmt = strjoina("MESSAGE=", format);
- DISABLE_WARNING_FORMAT_NONLITERAL;
- log_unit_struct(u, job_done_messages[result].log_level,
- msg_fmt, ident,
- "JOB_ID=%" PRIu32, job_id,
- "JOB_TYPE=%s", job_type_to_string(t),
- "JOB_RESULT=%s", job_result_to_string(result),
- LOG_UNIT_INVOCATION_ID(u),
- mid);
- REENABLE_WARNING;
+ c = t == JOB_START && result == JOB_DONE ? unit_find_failed_condition(u) : NULL;
+ if (c) {
+ /* Special case units that were skipped because of a failed condition check so that
+ * we can add more information to the message. */
+ if (c->trigger)
+ log_unit_struct(
+ u,
+ job_done_messages[result].log_level,
+ "MESSAGE=%s was skipped because all trigger condition checks failed.",
+ ident,
+ "JOB_ID=%" PRIu32, job_id,
+ "JOB_TYPE=%s", job_type_to_string(t),
+ "JOB_RESULT=%s", job_result_to_string(result),
+ LOG_UNIT_INVOCATION_ID(u),
+ mid);
+ else
+ log_unit_struct(
+ u,
+ job_done_messages[result].log_level,
+ "MESSAGE=%s was skipped because of a failed condition check (%s=%s%s).",
+ ident,
+ condition_type_to_string(c->type),
+ c->negate ? "!" : "",
+ c->parameter,
+ "JOB_ID=%" PRIu32, job_id,
+ "JOB_TYPE=%s", job_type_to_string(t),
+ "JOB_RESULT=%s", job_result_to_string(result),
+ LOG_UNIT_INVOCATION_ID(u),
+ mid);
+ } else {
+ const char *msg_fmt = strjoina("MESSAGE=", format);
+
+ DISABLE_WARNING_FORMAT_NONLITERAL;
+ log_unit_struct(u, job_done_messages[result].log_level,
+ msg_fmt, ident,
+ "JOB_ID=%" PRIu32, job_id,
+ "JOB_TYPE=%s", job_type_to_string(t),
+ "JOB_RESULT=%s", job_result_to_string(result),
+ LOG_UNIT_INVOCATION_ID(u),
+ mid);
+ REENABLE_WARNING;
+ }
}
if (do_console) {