From 477d08b3a97fa5b18b61da61d300a81ea9adb3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 25 Aug 2026 11:00:37 +0200 Subject: [PATCH] integritysetup: convert to VERB_COMMAND and add --introspect-cli MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Standard parse_argv() func is added. --version is now accepted (previously only the help forms were recognized, via argv_looks_like_help()). The synopsis changes from "systemd-integritysetup COMMAND ..." to the standard "systemd-integritysetup [OPTION…] COMMAND …", and the help output gains an Options section. "help" as the first argument keeps working via the hidden common help verb. Previously, we'd just print help and exit with success if no arguments were given. This seems unexpected and wrong. The program now prints the usual error message: Command verb required (one of attach, detach, help). --- src/integritysetup/integritysetup.c | 70 +++++++++++-------- .../units/TEST-74-AUX-UTILS.introspect-cli.sh | 1 + 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/integritysetup/integritysetup.c b/src/integritysetup/integritysetup.c index bf2f40b0d4..461be60905 100644 --- a/src/integritysetup/integritysetup.c +++ b/src/integritysetup/integritysetup.c @@ -1,22 +1,20 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include +#include "sd-json.h" + #include "alloc-util.h" -#include "argv-util.h" +#include "build.h" #include "cryptsetup-util.h" #include "dlopen-note.h" #include "fileio.h" -#include "format-table.h" -#include "help-util.h" #include "integrity-util.h" #include "log.h" #include "main-func.h" #include "path-util.h" #include "string-table.h" #include "string-util.h" -#include "strv.h" #include "time-util.h" #include "verbs.h" @@ -43,25 +41,11 @@ static const char* const dm_integrity_algorithm_table[_INTEGRITY_ALGORITHM_MAX] DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(dm_integrity_algorithm, IntegrityAlgorithm); -static int help(void) { - _cleanup_(table_unrefp) Table *verbs = NULL; - int r; - - r = verbs_get_help_table(&verbs); - if (r < 0) - return r; - - help_cmdline("COMMAND ..."); - help_abstract("Attach or detach an integrity protected block device."); - - help_section("Commands"); - r = table_print_or_warn(verbs); - if (r < 0) - return r; - - help_man_page_reference("systemd-integritysetup@.service", "8"); - return 0; -} +COMMAND( + "systemd-integritysetup\0", + "Attach or detach an integrity protected block device.", + .man_pages = "systemd-integritysetup@.service.8\0", +); static int load_key_file( const char *key_file, @@ -197,23 +181,51 @@ static int verb_detach(int argc, char *argv[], uintptr_t _data, void *userdata) return 0; } +VERB_COMMON_HELP_AUTO_HIDDEN(); + +static int parse_argv(int argc, char *argv[], char ***ret_args) { + assert(argc >= 0); + assert(argv); + assert(ret_args); + + OptionParser opts = { argc, argv }; + + FOREACH_OPTION_OR_RETURN(c, &opts) + switch (c) { + + OPTION_COMMON_HELP: + return command_print_help(); + + OPTION_COMMON_VERSION: + return version(); + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); + } + + *ret_args = option_parser_get_args(&opts); + return 1; +} + static int run(int argc, char *argv[]) { int r; - LIBCRYPTSETUP_NOTE(required); - - if (argv_looks_like_help(argc, argv)) - return help(); + char **args = NULL; + r = parse_argv(argc, argv, &args); + if (r <= 0) + return r; log_setup(); + LIBCRYPTSETUP_NOTE(required); + r = dlopen_cryptsetup(LOG_ERR); if (r < 0) return r; umask(0022); - return dispatch_verb(strv_skip(argv, 1), /* userdata= */ NULL); + return dispatch_verb(args, /* userdata= */ NULL); } DEFINE_MAIN_FUNCTION(run); diff --git a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh index ce9124696b..8cc37d3559 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -73,6 +73,7 @@ INTROSPECTABLE=( systemd-import systemd-import-fs systemd-inhibit + systemd-integritysetup systemd-journal-gatewayd systemd-journal-remote systemd-journal-upload