valeriyvdovin / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone
923a60
From 0204371780cbcae7635544abc61846d33d04c317 Mon Sep 17 00:00:00 2001
923a60
From: Michal Schmidt <mschmidt@redhat.com>
923a60
Date: Mon, 20 Jul 2015 18:36:12 +0200
923a60
Subject: [PATCH] core: unit_get_status_message_format() never returns NULL
923a60
923a60
unit_get_status_message_format() is used only with one of JOB_START,
923a60
JOB_STOP, JOB_RELOAD, all of which have fallback message strings
923a60
defined, so the function may never return NULL.
923a60
923a60
(cherry picked from commit b5bf308ba50ab0bac0f0caec2d8e4d5c75c107d0)
923a60
923a60
Related: #1506256
923a60
---
923a60
 src/core/unit.c | 13 +++----------
923a60
 1 file changed, 3 insertions(+), 10 deletions(-)
923a60
923a60
diff --git a/src/core/unit.c b/src/core/unit.c
923a60
index a33cbdf73f..22d9beed76 100644
923a60
--- a/src/core/unit.c
923a60
+++ b/src/core/unit.c
923a60
@@ -1332,10 +1332,9 @@ _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
+        assert(t == JOB_START || t == JOB_STOP || t == JOB_RELOAD);
923a60
 
923a60
-        if (t == JOB_START || t == JOB_STOP) {
923a60
+        if (t != JOB_RELOAD) {
923a60
                 format_table = &UNIT_VTABLE(u)->status_message_formats;
923a60
                 if (format_table) {
923a60
                         format = format_table->starting_stopping[t == JOB_STOP];
923a60
@@ -1349,10 +1348,8 @@ _pure_ static const char* unit_get_status_message_format(Unit *u, JobType t) {
923a60
                 return "Starting %s.";
923a60
         else if (t == JOB_STOP)
923a60
                 return "Stopping %s.";
923a60
-        else if (t == JOB_RELOAD)
923a60
+        else
923a60
                 return "Reloading %s.";
923a60
-
923a60
-        return NULL;
923a60
 }
923a60
 
923a60
 static void unit_status_print_starting_stopping(Unit *u, JobType t) {
923a60
@@ -1361,8 +1358,6 @@ static void unit_status_print_starting_stopping(Unit *u, JobType t) {
923a60
         assert(u);
923a60
 
923a60
         format = unit_get_status_message_format(u, t);
923a60
-        if (!format)
923a60
-                return;
923a60
 
923a60
         DISABLE_WARNING_FORMAT_NONLITERAL;
923a60
         unit_status_printf(u, "", format);
923a60
@@ -1385,8 +1380,6 @@ static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
923a60
         /* We log status messages for all units and all operations. */
923a60
 
923a60
         format = unit_get_status_message_format(u, t);
923a60
-        if (!format)
923a60
-                return;
923a60
 
923a60
         DISABLE_WARNING_FORMAT_NONLITERAL;
923a60
         snprintf(buf, sizeof(buf), format, unit_description(u));