]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
busctl: use STRV_FOREACH in the usual fashion
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 19 Nov 2024 15:26:03 +0000 (16:26 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 27 Mar 2025 11:04:30 +0000 (12:04 +0100)
Also put positive branch first, do not use 'i' as a char** variable name.

src/busctl/busctl.c

index 2e25e6a00664a913ea21dc008de314e1aac00a9c..21f45df6822d3ec03475ab10876dd02840a7a8e5 100644 (file)
@@ -547,9 +547,25 @@ static int tree(int argc, char **argv, void *userdata) {
         if (r < 0)
                 return r;
 
-        if (argc <= 1) {
+        char **args = strv_skip(argv, 1);
+        if (args)
+                STRV_FOREACH(arg, args) {
+                        int q;
+
+                        if (arg != args)
+                                puts("");
+
+                        if (args[1]) {
+                                pager_open(arg_pager_flags);
+                                printf("Service %s%s%s:\n", ansi_highlight(), *arg, ansi_normal());
+                        }
+
+                        q = tree_one(bus, *arg);
+                        if (q < 0 && r >= 0)
+                                r = q;
+                }
+        else {
                 _cleanup_strv_free_ char **names = NULL;
-                bool not_first = false;
 
                 r = sd_bus_list_names(bus, &names, NULL);
                 if (r < 0)
@@ -557,42 +573,25 @@ static int tree(int argc, char **argv, void *userdata) {
 
                 pager_open(arg_pager_flags);
 
-                STRV_FOREACH(i, names) {
+                STRV_FOREACH(name, names) {
                         int q;
 
-                        if (!arg_unique && (*i)[0] == ':')
+                        if (!arg_unique && (*name)[0] == ':')
                                 continue;
 
-                        if (!arg_acquired && (*i)[0] == ':')
+                        if (!arg_acquired && (*name)[0] == ':')
                                 continue;
 
-                        if (not_first)
-                                printf("\n");
-
-                        printf("Service %s%s%s:\n", ansi_highlight(), *i, ansi_normal());
+                        if (name != names)
+                                puts("");
 
-                        q = tree_one(bus, *i);
-                        if (q < 0 && r >= 0)
-                                r = q;
-
-                        not_first = true;
-                }
-        } else
-                STRV_FOREACH(i, strv_skip(argv, 1)) {
-                        int q;
+                        printf("Service %s%s%s:\n", ansi_highlight(), *name, ansi_normal());
 
-                        if (i > argv+1)
-                                printf("\n");
-
-                        if (argv[2]) {
-                                pager_open(arg_pager_flags);
-                                printf("Service %s%s%s:\n", ansi_highlight(), *i, ansi_normal());
-                        }
-
-                        q = tree_one(bus, *i);
+                        q = tree_one(bus, *name);
                         if (q < 0 && r >= 0)
                                 r = q;
                 }
+        }
 
         return r;
 }