From 378e6c544b9e9c99bd02a9466500184bf68051ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 26 Aug 2026 10:18:16 +0200 Subject: [PATCH] udevd: convert to VERB_COMMAND and add --introspect-cli MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit systemd-udevd is the same binary as udevadm, so the introspection data describes both commands, from either name. The COMMAND intentionally owns no verbs — all of udevadm's verbs are defined in udevadm.c right after its own COMMAND, so that they are attributed to it. The -V/--version output (GIT_VERSION) is preserved. --- src/udev/udev-config.c | 39 ++++++++----------- .../units/TEST-74-AUX-UTILS.introspect-cli.sh | 17 ++++++++ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/udev/udev-config.c b/src/udev/udev-config.c index c108985c4d..0733f41872 100644 --- a/src/udev/udev-config.c +++ b/src/udev/udev-config.c @@ -2,14 +2,14 @@ #include +#include "sd-json.h" + #include "conf-parser.h" #include "cpu-set-util.h" #include "daemon-util.h" #include "fd-util.h" #include "fileio.h" -#include "format-table.h" #include "hashmap.h" -#include "help-util.h" #include "limits-util.h" #include "options.h" #include "parse-util.h" @@ -25,6 +25,7 @@ #include "udev-rules.h" #include "udev-util.h" #include "udev-worker.h" +#include "verbs.h" #include "version.h" #define WORKER_NUM_MAX UINT64_C(2048) @@ -149,26 +150,15 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat return 0; } -static int help(void) { - _cleanup_(table_unrefp) Table *options = NULL; - int r; - - r = option_parser_get_help_table_ns("udevd", &options); - if (r < 0) - return r; - - help_cmdline("[OPTIONS...]"); - help_abstract("Rule-based manager for device events and files."); - - help_section("Options"); - - r = table_print_or_warn(options); - if (r < 0) - return r; - - help_man_page_reference("systemd-udevd.service", "8"); - return 0; -} +/* systemd-udevd is the same binary as udevadm. This COMMAND intentionally owns no verbs: all of + * udevadm's verbs are defined in udevadm.c right after its own COMMAND, so that they are attributed + * to it. */ +COMMAND( + "systemd-udevd\0", + "Rule-based manager for device events and files.", + .man_pages = "systemd-udevd.service(8)\0", + .option_namespace = "udevd", +); static int parse_argv(int argc, char *argv[], UdevConfig *config) { int r; @@ -185,7 +175,7 @@ static int parse_argv(int argc, char *argv[], UdevConfig *config) { OPTION_NAMESPACE("udevd"): {} OPTION_COMMON_HELP: - return help(); + return command_print_help_name("systemd-udevd"); OPTION('V', "version", NULL, "Show package version"): printf("%s\n", GIT_VERSION); @@ -234,6 +224,9 @@ static int parse_argv(int argc, char *argv[], UdevConfig *config) { else config->timeout_signal = r; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } return 1; diff --git a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh index 40116bd870..8c6e0e0ad3 100755 --- a/test/units/TEST-74-AUX-UTILS.introspect-cli.sh +++ b/test/units/TEST-74-AUX-UTILS.introspect-cli.sh @@ -136,6 +136,7 @@ INTROSPECTABLE=( systemd-tpm2-clear systemd-tpm2-setup systemd-tty-ask-password-agent + systemd-udevd systemd-umount systemd-update-done systemd-validatefs @@ -222,6 +223,22 @@ udevadm --introspect-cli | jq -e \ udevadm lock -h | grep -E '^> udevadm .* lock .* COMMAND$' udevadm lock -h | grep -E '^> udevadm .* lock .* --print$' +# udevadm is also systemd-udevd +udevadm --introspect-cli | jq -e \ + '[.commands[].names[0]] | sort == ["systemd-udevd", "udevadm"]' + +# The systemd-udevd command must own no verbs: the help-verb check in the loop above relies on +# this to never run 'systemd-udevd help', which would start the daemon. +udevadm --introspect-cli | jq -e \ + '.commands[] | select(.names[0] == "systemd-udevd") | (.verbs // []) == []' + +# Each subcommand's help and introspection must work +for v in cat control hwdb info lock monitor settle test test-builtin trigger verify wait; do + udevadm "$v" --help >/dev/null + udevadm "$v" --introspect-cli | jq -e \ + '.mediaType == "application/vnd.io.systemd.cli-introspection-0"' +done + # systemd is optionally a multicall binary that also provides systemd-executor if [[ "$(readlink "$(command -v systemd-executor)" 2>/dev/null)" == systemd ]]; then systemd --introspect-cli | jq -e \