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