From: Zbigniew Jędrzejewski-Szmek Date: Tue, 19 Nov 2024 15:26:03 +0000 (+0100) Subject: busctl: use STRV_FOREACH in the usual fashion X-Git-Tag: v258-rc1~987^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=635accef79c64f275e3d732bb093dbb8a7cd9da7;p=thirdparty%2Fsystemd.git busctl: use STRV_FOREACH in the usual fashion Also put positive branch first, do not use 'i' as a char** variable name. --- diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index 2e25e6a0066..21f45df6822 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -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; }