]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: move printing of state to the printing func. 26867/head
authorDavid Tardon <dtardon@redhat.com>
Fri, 17 Mar 2023 09:43:54 +0000 (10:43 +0100)
committerDavid Tardon <dtardon@redhat.com>
Fri, 17 Mar 2023 13:50:40 +0000 (14:50 +0100)
No functional change, just refactoring.

src/systemctl/systemctl-list-dependencies.c

index 7953943223da3a75aa4c6ccf8963517fa2ef94dd..a9121f1035655426badaeea78db3779694b60ed0 100644 (file)
@@ -8,11 +8,36 @@
 #include "systemctl.h"
 #include "terminal-util.h"
 
-static int list_dependencies_print(const char *name, int level, unsigned branches, bool last) {
+static int list_dependencies_print(const char *name, UnitActiveState state, int level, unsigned branches, bool last) {
         _cleanup_free_ char *n = NULL;
         size_t max_len = MAX(columns(),20u);
         size_t len = 0;
 
+        if (arg_plain || state == _UNIT_ACTIVE_STATE_INVALID)
+                printf("  ");
+        else {
+                const char *on;
+
+                switch (state) {
+                case UNIT_ACTIVE:
+                case UNIT_RELOADING:
+                case UNIT_ACTIVATING:
+                        on = ansi_highlight_green();
+                        break;
+
+                case UNIT_INACTIVE:
+                case UNIT_DEACTIVATING:
+                        on = ansi_normal();
+                        break;
+
+                default:
+                        on = ansi_highlight_red();
+                        break;
+                }
+
+                printf("%s%s%s ", on, special_glyph(unit_active_state_to_glyph(state)), ansi_normal());
+        }
+
         if (!arg_plain) {
                 for (int i = level - 1; i >= 0; i--) {
                         len += 2;
@@ -108,32 +133,7 @@ static int list_dependencies_one(
                                 continue;
                 }
 
-                if (arg_plain)
-                        printf("  ");
-                else {
-                        const char *on;
-
-                        switch (active_state) {
-                        case UNIT_ACTIVE:
-                        case UNIT_RELOADING:
-                        case UNIT_ACTIVATING:
-                                on = ansi_highlight_green();
-                                break;
-
-                        case UNIT_INACTIVE:
-                        case UNIT_DEACTIVATING:
-                                on = ansi_normal();
-                                break;
-
-                        default:
-                                on = ansi_highlight_red();
-                                break;
-                        }
-
-                        printf("%s%s%s ", on, special_glyph(unit_active_state_to_glyph(active_state)), ansi_normal());
-                }
-
-                r = list_dependencies_print(*c, level, branches, /* last = */ c[1] == NULL && !circular);
+                r = list_dependencies_print(*c, active_state, level, branches, /* last = */ c[1] == NULL && !circular);
                 if (r < 0)
                         return r;
 
@@ -145,8 +145,7 @@ static int list_dependencies_one(
         }
 
         if (circular && !arg_plain) {
-                printf("  ");
-                r = list_dependencies_print("...", level, branches, /* last = */ true);
+                r = list_dependencies_print("...", _UNIT_ACTIVE_STATE_INVALID, level, branches, /* last = */ true);
                 if (r < 0)
                         return r;
         }