imdsd: 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-18 16:54:09 +02:00
parent 431e3f7def
commit f17f7cc35e
2 changed files with 13 additions and 35 deletions
+12 -35
View File
@@ -29,10 +29,8 @@
#include "fd-util.h"
#include "fileio.h"
#include "format-ifname.h"
#include "format-table.h"
#include "hash-funcs.h"
#include "hashmap.h"
#include "help-util.h"
#include "imds-util.h"
#include "in-addr-util.h"
#include "io-util.h"
@@ -41,7 +39,6 @@
#include "log.h"
#include "main-func.h"
#include "netlink-util.h"
#include "options.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
@@ -54,6 +51,7 @@
#include "utf8.h"
#include "varlink-io.systemd.InstanceMetadata.h"
#include "varlink-util.h"
#include "verbs.h"
#include "web-util.h"
#include "xattr-util.h"
@@ -141,6 +139,13 @@ STATIC_DESTRUCTOR_REGISTER(arg_token_header_name, freep);
STATIC_DESTRUCTOR_REGISTER(arg_extra_header, strv_freep);
STATIC_DESTRUCTOR_REGISTER(arg_well_known_key, imds_well_known_key_free);
COMMAND(
"systemd-imdsd\0",
"Low-level IMDS data acquisition.",
.argspec = "KEY\0",
.man_pages = "systemd-imdsd@.service.8\0",
);
typedef struct Context Context;
typedef struct ChildData {
@@ -2192,37 +2197,6 @@ static int vl_server(void) {
return 0;
}
static int help(void) {
_cleanup_(table_unrefp) Table *options = NULL, *endpoint_options = NULL;
int r;
r = option_parser_get_help_table(&options);
if (r < 0)
return r;
r = option_parser_get_help_table_group("Manual Endpoint Configuration", &endpoint_options);
if (r < 0)
return r;
(void) table_sync_column_widths(0, options, endpoint_options);
help_cmdline("[OPTIONS...] KEY");
help_abstract("Low-level IMDS data acquisition.");
help_section("Options");
r = table_print_or_warn(options);
if (r < 0)
return r;
help_section("Manual Endpoint Configuration");
r = table_print_or_warn(endpoint_options);
if (r < 0)
return r;
help_man_page_reference("systemd-imdsd@.service", "8");
return 0;
}
static bool http_header_name_valid(const char *a) {
return a && ascii_is_valid(a) && !string_has_cc(a, /* ok= */ NULL) && !strchr(a, ':');
}
@@ -2239,7 +2213,7 @@ static int parse_argv(int argc, char *argv[]) {
switch (c) {
OPTION_COMMON_HELP:
return help();
return command_print_help("systemd-imdsd");
OPTION_COMMON_VERSION:
return version();
@@ -2484,6 +2458,9 @@ static int parse_argv(int argc, char *argv[]) {
return r;
break;
}
OPTION_COMMON_INTROSPECT_CLI:
return introspect_cli(SD_JSON_FORMAT_OFF);
}
if (arg_vendor || arg_token_url || arg_refresh_header_name || arg_data_url || arg_data_url_suffix || arg_token_header_name || arg_extra_header)
@@ -49,6 +49,7 @@ INTROSPECTABLE=(
systemd-hwdb
systemd-id128
systemd-imds
systemd-imdsd
systemd-inhibit
systemd-journal-gatewayd
systemd-journal-remote