richardphibel / rpms / systemd

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