]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: always print circular deps. at the end
authorDavid Tardon <dtardon@redhat.com>
Fri, 17 Mar 2023 09:11:38 +0000 (10:11 +0100)
committerDavid Tardon <dtardon@redhat.com>
Fri, 17 Mar 2023 09:47:04 +0000 (10:47 +0100)
Before:
a.target
○ └─b.target
    ├─...
●   └─paths.target

After:
a.target
○ └─b.target
●   ├─paths.target
    └─...

src/systemctl/systemctl-list-dependencies.c

index 95949ab763a1e4940a9eb521ae4b4863a51e4f86..1da5cf5075ed95db40ca650e81815d5c4e2353d8 100644 (file)
@@ -64,6 +64,7 @@ static int list_dependencies_one(
 
         _cleanup_strv_free_ char **deps = NULL;
         int r;
+        bool circular = false;
 
         assert(bus);
         assert(name);
@@ -84,12 +85,7 @@ static int list_dependencies_one(
                 UnitActiveState active_state;
 
                 if (strv_contains(*units, *c)) {
-                        if (!arg_plain) {
-                                printf("  ");
-                                r = list_dependencies_print("...", level, branches, /* last = */ c[1] == NULL);
-                                if (r < 0)
-                                        return r;
-                        }
+                        circular = true;
                         continue;
                 }
 
@@ -138,7 +134,7 @@ static int list_dependencies_one(
                         printf("%s%s%s ", on, special_glyph(unit_active_state_to_glyph(active_state)), ansi_normal());
                 }
 
-                r = list_dependencies_print(*c, level, branches, c[1] == NULL);
+                r = list_dependencies_print(*c, level, branches, /* last = */ c[1] == NULL && !circular);
                 if (r < 0)
                         return r;
 
@@ -149,6 +145,13 @@ static int list_dependencies_one(
                 }
         }
 
+        if (circular && !arg_plain) {
+                printf("  ");
+                r = list_dependencies_print("...", level, branches, /* last = */ true);
+                if (r < 0)
+                        return r;
+        }
+
         if (!arg_plain)
                 strv_remove(*units, name);