]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: always set output arg in unit_status_string()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 1 Jul 2021 08:19:06 +0000 (10:19 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 1 Jul 2021 13:30:35 +0000 (15:30 +0200)
As requested in https://github.com/systemd/systemd/pull/20058#pullrequestreview-696942153.

src/core/unit.c

index 57e4acff3a5b437f4b16d7bbf8b8175c8e4fa9c5..30afd5a7767a80e20c907486a7f5fa0686999a64 100644 (file)
@@ -1340,27 +1340,35 @@ const char* unit_description(Unit *u) {
         return strna(u->id);
 }
 
-const char* unit_status_string(Unit *u, char **combined) {
+const char* unit_status_string(Unit *u, char **ret_combined_buffer) {
         assert(u);
         assert(u->id);
 
         /* Return u->id, u->description, or "{u->id} - {u->description}".
          * Versions with u->description are only used if it is set.
-         * The last option is used if configured and the caller provided 'combined' pointer. */
+         * The last option is used if configured and the caller provided the 'ret_combined_buffer'
+         * pointer.
+         *
+         * Note that *ret_combined_buffer may be set to NULL. */
 
         if (!u->description ||
-            streq(u->description, u->id) ||
             u->manager->status_unit_format == STATUS_UNIT_FORMAT_NAME ||
-            (u->manager->status_unit_format == STATUS_UNIT_FORMAT_COMBINED && !combined))
+            (u->manager->status_unit_format == STATUS_UNIT_FORMAT_COMBINED && !ret_combined_buffer) ||
+            streq(u->description, u->id)) {
+
+                if (ret_combined_buffer)
+                        *ret_combined_buffer = NULL;
                 return u->id;
+        }
 
-        if (u->description && u->manager->status_unit_format == STATUS_UNIT_FORMAT_COMBINED && combined) {
-                char *t = strjoin(u->id, " - ", u->description);
-                if (t) {
-                        *combined = t;
-                        return t;
+        if (ret_combined_buffer) {
+                if (u->manager->status_unit_format == STATUS_UNIT_FORMAT_COMBINED) {
+                        *ret_combined_buffer = strjoin(u->id, " - ", u->description);
+                        if (*ret_combined_buffer)
+                                return *ret_combined_buffer;
+                        log_oom(); /* Fall back to ->description */
                 } else
-                        log_oom();
+                        *ret_combined_buffer = NULL;
         }
 
         return u->description;