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

The custom help() is replaced by a COMMAND() description, and
--introspect-cli is added. The man page is adjusted to match.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-17 13:21:31 +02:00
parent 4df2325694
commit d1c345a079
3 changed files with 23 additions and 29 deletions
+5 -1
View File
@@ -46,7 +46,11 @@
<para><filename>systemd-pcrnvdone.service</filename></para> <para><filename>systemd-pcrnvdone.service</filename></para>
<para><filename>systemd-pcrphase-factory-reset.service</filename></para> <para><filename>systemd-pcrphase-factory-reset.service</filename></para>
<para><filename>systemd-pcrphase-storage-target-mode.service</filename></para> <para><filename>systemd-pcrphase-storage-target-mode.service</filename></para>
<para><filename>/usr/lib/systemd/systemd-pcrextend</filename> <optional><replaceable>STRING</replaceable></optional></para> <para><filename>/usr/lib/systemd/systemd-pcrextend</filename> <replaceable>WORD</replaceable></para>
<para><filename>/usr/lib/systemd/systemd-pcrextend</filename> <option>--file-system=<replaceable>PATH</replaceable></option></para>
<para><filename>/usr/lib/systemd/systemd-pcrextend</filename> <option>--machine-id</option></para>
<para><filename>/usr/lib/systemd/systemd-pcrextend</filename> <option>--product-id</option></para>
<para><filename>/usr/lib/systemd/systemd-pcrextend</filename> <option>--login=<replaceable>UID</replaceable>|<replaceable>USER</replaceable></option></para>
</refsynopsisdiv> </refsynopsisdiv>
<refsect1> <refsect1>
+17 -28
View File
@@ -10,11 +10,8 @@
#include "dlopen-note.h" #include "dlopen-note.h"
#include "efi-loader.h" #include "efi-loader.h"
#include "escape.h" #include "escape.h"
#include "format-table.h"
#include "help-util.h"
#include "json-util.h" #include "json-util.h"
#include "main-func.h" #include "main-func.h"
#include "options.h"
#include "parse-argument.h" #include "parse-argument.h"
#include "pcrextend-util.h" #include "pcrextend-util.h"
#include "string-table.h" #include "string-table.h"
@@ -26,6 +23,7 @@
#include "userdb.h" #include "userdb.h"
#include "varlink-io.systemd.PCRExtend.h" #include "varlink-io.systemd.PCRExtend.h"
#include "varlink-util.h" #include "varlink-util.h"
#include "verbs.h"
static bool arg_graceful = false; static bool arg_graceful = false;
static char *arg_tpm2_device = NULL; static char *arg_tpm2_device = NULL;
@@ -45,32 +43,20 @@ STATIC_DESTRUCTOR_REGISTER(arg_file_system, freep);
STATIC_DESTRUCTOR_REGISTER(arg_nvpcr_name, freep); STATIC_DESTRUCTOR_REGISTER(arg_nvpcr_name, freep);
STATIC_DESTRUCTOR_REGISTER(arg_login, user_record_unrefp); STATIC_DESTRUCTOR_REGISTER(arg_login, user_record_unrefp);
COMMAND(
"systemd-pcrextend\0",
"Extend a TPM2 PCR with boot phase, machine ID, file system ID or user record.",
.argspec =
"WORD\0"
"--file-system=PATH\0"
"--machine-id\0"
"--product-id\0"
"--login=UID|USER\0",
.man_pages = "systemd-pcrextend.8\0",
);
#define EXTENSION_STRING_SAFE_LIMIT 1024 #define EXTENSION_STRING_SAFE_LIMIT 1024
static int help(void) {
_cleanup_(table_unrefp) Table *options = NULL;
int r;
r = option_parser_get_help_table(&options);
if (r < 0)
return r;
help_cmdline("[OPTIONS...] WORD");
help_cmdline("[OPTIONS...] --file-system=PATH");
help_cmdline("[OPTIONS...] --machine-id");
help_cmdline("[OPTIONS...] --product-id");
help_cmdline("[OPTIONS...] --login=UID|USER");
help_abstract("Extend a TPM2 PCR with boot phase, machine ID, file system ID or user record.");
help_section("Options");
r = table_print_or_warn(options);
if (r < 0)
return r;
help_man_page_reference("systemd-pcrextend", "8");
return 0;
}
static int parse_argv(int argc, char *argv[], char ***ret_args) { static int parse_argv(int argc, char *argv[], char ***ret_args) {
assert(argc >= 0); assert(argc >= 0);
assert(argv); assert(argv);
@@ -82,7 +68,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
switch (c) { switch (c) {
OPTION_COMMON_HELP: OPTION_COMMON_HELP:
return help(); return command_print_help("systemd-pcrextend");
OPTION_COMMON_VERSION: OPTION_COMMON_VERSION:
return version(); return version();
@@ -185,6 +171,9 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
if (arg_event_type < 0) if (arg_event_type < 0)
return log_error_errno(arg_event_type, "Failed to parse --event-type= argument: %s", opts.arg); return log_error_errno(arg_event_type, "Failed to parse --event-type= argument: %s", opts.arg);
break; break;
OPTION_COMMON_INTROSPECT_CLI:
return introspect_cli(SD_JSON_FORMAT_OFF);
} }
if (!!arg_file_system + arg_machine_id + arg_product_id + !!arg_login > 1) if (!!arg_file_system + arg_machine_id + arg_product_id + !!arg_login > 1)
@@ -46,6 +46,7 @@ INTROSPECTABLE=(
systemd-notify systemd-notify
systemd-oomd systemd-oomd
systemd-path systemd-path
systemd-pcrextend
systemd-pty-forward systemd-pty-forward
systemd-socket-activate systemd-socket-activate
systemd-tty-ask-password-agent systemd-tty-ask-password-agent