From 24fb06f158f19258f09ee37d98aeec2670c61ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 17 Aug 2026 13:36:14 +0200 Subject: [PATCH] oomctl: convert to VERB_COMMAND and add --introspect-cli The custom help() is replaced by a COMMAND() description, and --introspect-cli is added. --- src/oom/oomctl.c | 63 ++++--------------- .../units/TEST-74-AUX-UTILS.introspect-cli.sh | 1 + 2 files changed, 13 insertions(+), 51 deletions(-) diff --git a/src/oom/oomctl.c b/src/oom/oomctl.c index 8b5051ebd0..7238a0554b 100644 --- a/src/oom/oomctl.c +++ b/src/oom/oomctl.c @@ -1,69 +1,27 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "sd-bus.h" +#include "sd-json.h" -#include "alloc-util.h" #include "build.h" #include "bus-error.h" #include "bus-locator.h" #include "bus-message-util.h" -#include "format-table.h" #include "log.h" #include "main-func.h" -#include "options.h" #include "pager.h" -#include "pretty-print.h" #include "verbs.h" static PagerFlags arg_pager_flags = 0; -static int help(void) { - _cleanup_free_ char *link = NULL; - _cleanup_(table_unrefp) Table *options = NULL, *verbs = NULL; - int r; +COMMAND( + "oomctl\0", + "Manage or inspect the userspace OOM killer.", + .man_pages = "oomctl.1\0", + .pager_flags = &arg_pager_flags, +); - pager_open(arg_pager_flags); - - r = terminal_urlify_man("oomctl", "1", &link); - if (r < 0) - return log_oom(); - - r = verbs_get_help_table(&verbs); - if (r < 0) - return r; - - r = option_parser_get_help_table(&options); - if (r < 0) - return r; - - (void) table_sync_column_widths(0, verbs, options); - - printf("%s [OPTIONS...] COMMAND ...\n\n" - "%sManage or inspect the userspace OOM killer.%s\n" - "\n%sCommands:%s\n", - program_invocation_short_name, - ansi_highlight(), - ansi_normal(), - ansi_underline(), - ansi_normal()); - - r = table_print_or_warn(verbs); - if (r < 0) - return r; - - printf("\n%sOptions:%s\n", - ansi_underline(), - ansi_normal()); - - r = table_print_or_warn(options); - if (r < 0) - return r; - - printf("\nSee the %s for details.\n", link); - return 0; -} - -VERB_COMMON_HELP_HIDDEN(help); +VERB_COMMON_HELP_AUTO_HIDDEN("oomctl"); VERB_DEFAULT_NOARG(verb_dump_state, "dump", "Output the current state of systemd-oomd"); static int verb_dump_state(int argc, char *argv[], uintptr_t _data, void *userdata) { @@ -96,7 +54,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) { switch (c) { OPTION_COMMON_HELP: - return help(); + return command_print_help("oomctl"); OPTION_COMMON_VERSION: return version(); @@ -104,6 +62,9 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) { OPTION_COMMON_NO_PAGER: arg_pager_flags |= PAGER_DISABLE; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } *ret_args = option_parser_get_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 74d77244e6..c5daf8f199 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -18,6 +18,7 @@ INTROSPECTABLE=( importctl localectl networkctl + oomctl resolvectl systemd-ac-power systemd-analyze