dryang / rpms / systemd

Forked from rpms/systemd a year ago
Clone
923a60
From c571dc5f7d593a4526da9e19b35ae3d1ed11bfaa Mon Sep 17 00:00:00 2001
923a60
From: Michal Schmidt <mschmidt@redhat.com>
923a60
Date: Mon, 20 Jul 2015 17:18:13 +0200
923a60
Subject: [PATCH] core: always try harder to get unit status message format
923a60
 string
923a60
923a60
The starting/stopping messages are printed to the console only if the
923a60
corresponding format string is defined in the unit's vtable. To avoid
923a60
excessive messages on the console, the unit types whose start/stop
923a60
jobs are instantaneous had the format strings intentionally undefined.
923a60
When logging the same event to the journal, a fallback to generic
923a60
Starting/Stopping/Reloading messages is used.
923a60
923a60
The problem of excessive console messages with instantaneous jobs
923a60
is already resolved in a nicer way ("core: fix confusing logging of
923a60
instantaneous jobs"), so there's no longer a need to have two ways of
923a60
getting the format strings. Let's fold them into one function with
923a60
the fallback to generic message strings.
923a60
923a60
(cherry picked from commit a85ca902c9f7f5aa8f2f3e3299147733802cf09d)
923a60
923a60
Related: #1506256
923a60
---
923a60
 src/core/unit.c | 34 ++++++++++------------------------
923a60
 1 file changed, 10 insertions(+), 24 deletions(-)
923a60
923a60
diff --git a/src/core/unit.c b/src/core/unit.c
923a60
index 907a4bf7fd..a33cbdf73f 100644
923a60
--- a/src/core/unit.c
923a60
+++ b/src/core/unit.c
923a60
@@ -1328,32 +1328,21 @@ static bool unit_assert_test(Unit *u) {
923a60
 }
923a60
 
923a60
 _pure_ static const char* unit_get_status_message_format(Unit *u, JobType t) {
923a60
-        const UnitStatusMessageFormats *format_table;
923a60
-
923a60
-        assert(u);
923a60
-        assert(t >= 0);
923a60
-        assert(t < _JOB_TYPE_MAX);
923a60
-
923a60
-        if (t != JOB_START && t != JOB_STOP)
923a60
-                return NULL;
923a60
-
923a60
-        format_table = &UNIT_VTABLE(u)->status_message_formats;
923a60
-        if (!format_table)
923a60
-                return NULL;
923a60
-
923a60
-        return format_table->starting_stopping[t == JOB_STOP];
923a60
-}
923a60
-
923a60
-_pure_ static const char *unit_get_status_message_format_try_harder(Unit *u, JobType t) {
923a60
         const char *format;
923a60
+        const UnitStatusMessageFormats *format_table;
923a60
 
923a60
         assert(u);
923a60
         assert(t >= 0);
923a60
         assert(t < _JOB_TYPE_MAX);
923a60
 
923a60
-        format = unit_get_status_message_format(u, t);
923a60
-        if (format)
923a60
-                return format;
923a60
+        if (t == JOB_START || t == JOB_STOP) {
923a60
+                format_table = &UNIT_VTABLE(u)->status_message_formats;
923a60
+                if (format_table) {
923a60
+                        format = format_table->starting_stopping[t == JOB_STOP];
923a60
+                        if (format)
923a60
+                                return format;
923a60
+                }
923a60
+        }
923a60
 
923a60
         /* Return generic strings */
923a60
         if (t == JOB_START)
923a60
@@ -1371,9 +1360,6 @@ static void unit_status_print_starting_stopping(Unit *u, JobType t) {
923a60
 
923a60
         assert(u);
923a60
 
923a60
-        /* We only print status messages for selected units on
923a60
-         * selected operations. */
923a60
-
923a60
         format = unit_get_status_message_format(u, t);
923a60
         if (!format)
923a60
                 return;
923a60
@@ -1398,7 +1384,7 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
923a60
 
923a60
         /* We log status messages for all units and all operations. */
923a60
 
923a60
-        format = unit_get_status_message_format_try_harder(u, t);
923a60
+        format = unit_get_status_message_format(u, t);
923a60
         if (!format)
923a60
                 return;
923a60