anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0636-core-adjust-job-completion-message-log-levels.patch

aed857
From ea366cda56dc0550b9829e4d9e733cb8b70ffb30 Mon Sep 17 00:00:00 2001
aed857
From: Michal Schmidt <mschmidt@redhat.com>
aed857
Date: Tue, 21 Jul 2015 19:07:24 +0200
aed857
Subject: [PATCH] core: adjust job completion message log levels
aed857
aed857
We do not print all non-OK job completion status messages to the console
aed857
in red, because not all of them are plain errors. We do however log the
aed857
same messages as LOG_ERR.
aed857
aed857
Differentiate the log levels by deducing them from the job result in a
aed857
way that more or less matches the color of the console message.
aed857
aed857
(cherry picked from commit 64f575d2ab9a6743d3c7172b7591c88ba243cf1b)
aed857
aed857
Related: #1506256
aed857
---
aed857
 src/core/job.c | 19 +++++++++++++++----
aed857
 1 file changed, 15 insertions(+), 4 deletions(-)
aed857
aed857
diff --git a/src/core/job.c b/src/core/job.c
aed857
index 086050aa7..1861c8a63 100644
aed857
--- a/src/core/job.c
aed857
+++ b/src/core/job.c
aed857
@@ -714,6 +714,17 @@ static void job_print_status_message(Unit *u, JobType t, JobResult result) {
aed857
 static void job_log_status_message(Unit *u, JobType t, JobResult result) {
aed857
         const char *format;
aed857
         char buf[LINE_MAX];
aed857
+        static const int job_result_log_level[_JOB_RESULT_MAX] = {
aed857
+                [JOB_DONE]        = LOG_INFO,
aed857
+                [JOB_CANCELED]    = LOG_INFO,
aed857
+                [JOB_TIMEOUT]     = LOG_ERR,
aed857
+                [JOB_FAILED]      = LOG_ERR,
aed857
+                [JOB_DEPENDENCY]  = LOG_WARNING,
aed857
+                [JOB_SKIPPED]     = LOG_NOTICE,
aed857
+                [JOB_INVALID]     = LOG_INFO,
aed857
+                [JOB_ASSERT]      = LOG_WARNING,
aed857
+                [JOB_UNSUPPORTED] = LOG_WARNING,
aed857
+        };
aed857
 
aed857
         assert(u);
aed857
         assert(t >= 0);
aed857
@@ -738,14 +749,14 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
aed857
 
aed857
                 mid = result == JOB_DONE ? SD_MESSAGE_UNIT_STARTED : SD_MESSAGE_UNIT_FAILED;
aed857
                 log_unit_struct(u->id,
aed857
-                                result == JOB_DONE ? LOG_INFO : LOG_ERR,
aed857
+                                job_result_log_level[result],
aed857
                                 LOG_MESSAGE_ID(mid),
aed857
                                 LOG_MESSAGE("%s", buf),
aed857
                                 "RESULT=%s", job_result_to_string(result),
aed857
                                 NULL);
aed857
         } else if (t == JOB_STOP || t == JOB_RESTART)
aed857
                 log_unit_struct(u->id,
aed857
-                                result == JOB_DONE ? LOG_INFO : LOG_ERR,
aed857
+                                job_result_log_level[result],
aed857
                                 LOG_MESSAGE_ID(SD_MESSAGE_UNIT_STOPPED),
aed857
                                 LOG_MESSAGE("%s", buf),
aed857
                                 "RESULT=%s", job_result_to_string(result),
aed857
@@ -753,14 +764,14 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) {
aed857
 
aed857
         else if (t == JOB_RELOAD)
aed857
                 log_unit_struct(u->id,
aed857
-                                result == JOB_DONE ? LOG_INFO : LOG_ERR,
aed857
+                                job_result_log_level[result],
aed857
                                 LOG_MESSAGE_ID(SD_MESSAGE_UNIT_RELOADED),
aed857
                                 LOG_MESSAGE("%s", buf),
aed857
                                 "RESULT=%s", job_result_to_string(result),
aed857
                                 NULL);
aed857
         else
aed857
                 log_unit_struct(u->id,
aed857
-                                result == JOB_DONE ? LOG_INFO : LOG_ERR,
aed857
+                                job_result_log_level[result],
aed857
                                 LOG_MESSAGE("%s", buf),
aed857
                                 "RESULT=%s", job_result_to_string(result),
aed857
                                 NULL);