From cab5a18abb512e193aedb54279dae829a8ba2a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 15 Aug 2026 12:50:04 +0200 Subject: [PATCH] cgtop: convert to VERB_COMMAND and add --introspect-cli The custom help() is replaced by a COMMAND() description, and --introspect-cli is added. --- src/cgtop/cgtop.c | 46 ++++++------------- .../units/TEST-74-AUX-UTILS.introspect-cli.sh | 1 + 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 974a946142..f77b26d65b 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -3,28 +3,29 @@ #include #include +#include "sd-json.h" + #include "alloc-util.h" +#include "ansi-color.h" #include "build.h" #include "cgroup-show.h" #include "cgroup-util.h" #include "cpu-set-util.h" #include "fd-util.h" #include "fileio.h" -#include "format-table.h" #include "hashmap.h" #include "log.h" #include "main-func.h" -#include "options.h" #include "parse-argument.h" #include "parse-util.h" #include "path-util.h" -#include "pretty-print.h" #include "process-util.h" #include "procfs-util.h" #include "sort-util.h" #include "string-table.h" #include "terminal-util.h" #include "time-util.h" +#include "verbs.h" #include "virt.h" typedef struct Group { @@ -89,6 +90,13 @@ static PidsCount arg_count = COUNT_PIDS; static Order arg_order = ORDER_CPU; static CPUType arg_cpu_type = CPU_PERCENTAGE; +COMMAND( + "systemd-cgtop\0", + "Show top control groups by their resource usage.", + .argspec = "[CGROUP]\0", + .man_pages = "systemd-cgtop.1\0", +); + static const char *order_table[_ORDER_MAX] = { [ORDER_PATH] = "path", [ORDER_TASKS] = "tasks", @@ -684,33 +692,6 @@ static void display(Hashmap *a) { } } -static int help(void) { - _cleanup_free_ char *link = NULL; - _cleanup_(table_unrefp) Table *options = NULL; - int r; - - r = terminal_urlify_man("systemd-cgtop", "1", &link); - if (r < 0) - return log_oom(); - - r = option_parser_get_help_table(&options); - if (r < 0) - return r; - - printf("%s [OPTIONS...] [CGROUP]\n\n" - "%sShow top control groups by their resource usage.%s\n\n", - program_invocation_short_name, - ansi_highlight(), - ansi_normal()); - - r = table_print_or_warn(options); - if (r < 0) - return r; - - printf("\nSee the %s for details.\n", link); - return 0; -} - static int parse_argv(int argc, char *argv[]) { assert(argc >= 1); assert(argv); @@ -722,7 +703,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { OPTION_COMMON_HELP: - return help(); + return command_print_help("systemd-cgtop"); OPTION_COMMON_VERSION: return version(); @@ -822,6 +803,9 @@ static int parse_argv(int argc, char *argv[]) { OPTION_COMMON_MACHINE: arg_machine = opts.arg; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } size_t n_args = option_parser_get_n_args(&opts); diff --git a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh index 85c9cf269a..67d62cadba 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -20,6 +20,7 @@ INTROSPECTABLE=( systemd-bsod systemd-cat systemd-cgls + systemd-cgtop systemd-dissect systemd-firstboot systemd-hwdb