oomctl: convert to VERB_COMMAND and add --introspect-cli

The custom help() is replaced by a COMMAND() description, and
--introspect-cli is added.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-17 15:49:01 +02:00
parent 1ad1a47472
commit 24fb06f158
2 changed files with 13 additions and 51 deletions
+12 -51
View File
@@ -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);
@@ -18,6 +18,7 @@ INTROSPECTABLE=(
importctl
localectl
networkctl
oomctl
resolvectl
systemd-ac-power
systemd-analyze