diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c index 8149e755f5..fa95932985 100644 --- a/src/sysctl/sysctl.c +++ b/src/sysctl/sysctl.c @@ -1,26 +1,26 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include +#include "sd-json.h" + #include "alloc-util.h" #include "build.h" #include "conf-files.h" #include "constants.h" #include "creds-util.h" #include "errno-util.h" -#include "format-table.h" #include "glob-util.h" #include "hashmap.h" #include "log.h" #include "main-func.h" -#include "options.h" #include "pager.h" #include "path-util.h" #include "pretty-print.h" #include "string-util.h" #include "strv.h" #include "sysctl-util.h" +#include "verbs.h" static char **arg_prefixes = NULL; static CatFlags arg_cat_flags = CAT_CONFIG_OFF; @@ -31,6 +31,14 @@ static PagerFlags arg_pager_flags = 0; STATIC_DESTRUCTOR_REGISTER(arg_prefixes, strv_freep); +COMMAND( + "systemd-sysctl\0", + "Apply kernel sysctl settings.", + .argspec = "[CONFIGURATION FILE…]\0", + .man_pages = "systemd-sysctl.service.8\0", + .pager_flags = &arg_pager_flags, +); + typedef struct SysctlOption { char *key; char *value; @@ -317,48 +325,6 @@ static int cat_config(char **files) { return cat_files(NULL, files, arg_cat_flags); } -static int help(void) { - _cleanup_free_ char *link = NULL; - _cleanup_(table_unrefp) Table *commands = NULL, *options = NULL; - int r; - - r = terminal_urlify_man("systemd-sysctl.service", "8", &link); - if (r < 0) - return log_oom(); - - r = option_parser_get_help_table(&commands); - if (r < 0) - return r; - - r = option_parser_get_help_table_group("Options", &options); - if (r < 0) - return r; - - (void) table_sync_column_widths(0, commands, options); - - printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n" - "\n%sApplies kernel sysctl settings.%s\n" - "\n%sCommands:%s\n", - program_invocation_short_name, - ansi_highlight(), - ansi_normal(), - ansi_underline(), - ansi_normal()); - - r = table_print_or_warn(commands); - 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; -} - static int parse_argv(int argc, char *argv[], char ***remaining_args) { assert(argc >= 0); assert(argv); @@ -369,8 +335,10 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) { FOREACH_OPTION_OR_RETURN(c, &opts) switch (c) { + OPTION_GROUP("Commands"): {} + OPTION_COMMON_HELP: - return help(); + return command_print_help("systemd-sysctl"); OPTION_COMMON_VERSION: return version(); @@ -422,6 +390,9 @@ static int parse_argv(int argc, char *argv[], char ***remaining_args) { "Treat arguments as configuration lines"): arg_inline = true; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } *remaining_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 9a4dd5e167..50d1c50c38 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -87,6 +87,7 @@ INTROSPECTABLE=( systemd-storage-block systemd-storage-fs systemd-storagetm + systemd-sysctl systemd-sysinstall systemd-tpm2-clear systemd-tpm2-setup