4cad4c
From 9c543783dbe560f4dafa4c2f276e03a4bce0389e Mon Sep 17 00:00:00 2001
4cad4c
From: Lennart Poettering <lennart@poettering.net>
4cad4c
Date: Wed, 14 Nov 2018 11:08:16 +0100
4cad4c
Subject: [PATCH] job: when a job was skipped due to a failed condition, log
4cad4c
 about it
4cad4c
4cad4c
Previously we'd neither show console status output nor log output. Let's
4cad4c
fix that, and still log something.
4cad4c
4cad4c
(cherry picked from commit 9a80f2f4533883d272e6a436512aa7e88cedc549)
4cad4c
4cad4c
Related: #1737283
4cad4c
---
4cad4c
 src/core/job.c | 22 ++++++++++++++++++----
4cad4c
 1 file changed, 18 insertions(+), 4 deletions(-)
4cad4c
4cad4c
diff --git a/src/core/job.c b/src/core/job.c
4cad4c
index 561ea14682..b9eee91cf3 100644
4cad4c
--- a/src/core/job.c
4cad4c
+++ b/src/core/job.c
4cad4c
@@ -810,6 +810,10 @@ static void job_print_done_status_message(Unit *u, JobType t, JobResult result)
4cad4c
         if (t == JOB_RELOAD)
4cad4c
                 return;
4cad4c
 
4cad4c
+        /* No message if the job did not actually do anything due to failed condition. */
4cad4c
+        if (t == JOB_START && result == JOB_DONE && !u->condition_result)
4cad4c
+                return;
4cad4c
+
4cad4c
         if (!job_print_done_status_messages[result].word)
4cad4c
                 return;
4cad4c
 
4cad4c
@@ -865,6 +869,20 @@ static void job_log_done_status_message(Unit *u, uint32_t job_id, JobType t, Job
4cad4c
         if (log_on_console() && job_print_done_status_messages[result].word)
4cad4c
                 return;
4cad4c
 
4cad4c
+        /* Show condition check message if the job did not actually do anything due to failed condition. */
4cad4c
+        if (t == JOB_START && result == JOB_DONE && !u->condition_result) {
4cad4c
+                log_struct(LOG_INFO,
4cad4c
+                           "MESSAGE=Condition check resulted in %s being skipped.", unit_description(u),
4cad4c
+                           "JOB_ID=%" PRIu32, job_id,
4cad4c
+                           "JOB_TYPE=%s", job_type_to_string(t),
4cad4c
+                           "JOB_RESULT=%s", job_result_to_string(result),
4cad4c
+                           LOG_UNIT_ID(u),
4cad4c
+                           LOG_UNIT_INVOCATION_ID(u),
4cad4c
+                           "MESSAGE_ID=" SD_MESSAGE_UNIT_STARTED_STR);
4cad4c
+
4cad4c
+                return;
4cad4c
+        }
4cad4c
+
4cad4c
         format = job_get_done_status_message_format(u, t, result);
4cad4c
         if (!format)
4cad4c
                 return;
4cad4c
@@ -917,10 +935,6 @@ static void job_log_done_status_message(Unit *u, uint32_t job_id, JobType t, Job
4cad4c
 static void job_emit_done_status_message(Unit *u, uint32_t job_id, JobType t, JobResult result) {
4cad4c
         assert(u);
4cad4c
 
4cad4c
-        /* No message if the job did not actually do anything due to failed condition. */
4cad4c
-        if (t == JOB_START && result == JOB_DONE && !u->condition_result)
4cad4c
-                return;
4cad4c
-
4cad4c
         job_log_done_status_message(u, job_id, t, result);
4cad4c
         job_print_done_status_message(u, t, result);
4cad4c
 }