Convert machinectl to option and verb macros (#42117)

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-05-16 17:18:10 +02:00
committed by GitHub
17 changed files with 1232 additions and 1350 deletions
+1 -1
View File
@@ -339,7 +339,7 @@ static int make_bad(const char *prefix, uint64_t done, const char *suffix, char
return 0;
}
VERB(verb_status, "status", NULL, VERB_ANY, 1, VERB_DEFAULT, "Show status of current boot loader entry");
VERB_DEFAULT_NOARG(verb_status, "status", "Show status of current boot loader entry");
static int verb_status(int argc, char *argv[], uintptr_t _data, void *userdata) {
_cleanup_free_ char *path = NULL, *prefix = NULL, *suffix = NULL, *good = NULL, *bad = NULL;
uint64_t left, done;
+1 -2
View File
@@ -176,8 +176,7 @@ static void notify_bus_error(const sd_bus_error *error) {
(void) sd_notifyf(/* unset_environment= */ false, "BUSERROR=%s", error->name);
}
VERB(verb_list, "list", NULL, VERB_ANY, 1, VERB_DEFAULT,
"List bus names");
VERB_DEFAULT_NOARG(verb_list, "list", "List bus names");
static int verb_list(int argc, char *argv[], uintptr_t _data, void *userdata) {
_cleanup_strv_free_ char **acquired = NULL, **activatable = NULL;
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
+1 -2
View File
@@ -305,8 +305,7 @@ static int add_credentials_to_table(Table *t, bool encrypted) {
return 1; /* Creds dir set */
}
VERB(verb_list, "list", NULL, VERB_ANY, 1, VERB_DEFAULT,
"Show list of passed credentials");
VERB_DEFAULT_NOARG(verb_list, "list", "Show list of passed credentials");
static int verb_list(int argc, char *argv[], uintptr_t _data, void *userdata) {
_cleanup_(table_unrefp) Table *t = NULL;
int r, q;
+1 -1
View File
@@ -99,7 +99,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) {
return 1;
}
VERB(verb_status, "status", NULL, VERB_ANY, 1, VERB_DEFAULT, "Report current factory reset status");
VERB_DEFAULT_NOARG(verb_status, "status", "Report current factory reset status");
static int verb_status(int argc, char *argv[], uintptr_t _data, void *userdata) {
static const int exit_status_table[_FACTORY_RESET_MODE_MAX] = {
/* Report current mode also as via exit status, but only return a subset of states */
+1 -1
View File
@@ -545,7 +545,7 @@ static int get_hostname_based_on_flag(sd_bus *bus) {
return get_one_name(bus, attr, NULL);
}
VERB(verb_show_status, "status", NULL, VERB_ANY, 1, VERB_DEFAULT, "Show current hostname settings");
VERB_DEFAULT_NOARG(verb_show_status, "status", "Show current hostname settings");
static int verb_show_status(int argc, char *argv[], uintptr_t _data, void *userdata) {
sd_bus *bus = userdata;
int r;
+1 -1
View File
@@ -833,7 +833,7 @@ static int verb_export_raw(int argc, char *argv[], uintptr_t _data, void *userda
return transfer_image_common(bus, m);
}
VERB(verb_list_transfers, "list-transfers", NULL, VERB_ANY, 1, VERB_DEFAULT, "Show list of transfers in progress");
VERB_DEFAULT_NOARG(verb_list_transfers, "list-transfers", "Show list of transfers in progress");
static int verb_list_transfers(int argc, char *argv[], uintptr_t _data, void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
+1 -2
View File
@@ -147,8 +147,7 @@ static int print_status_info(StatusInfo *i) {
return table_print_or_warn(table);
}
VERB(verb_show_status, "status", NULL, VERB_ANY, 1, VERB_DEFAULT,
"Show current locale settings");
VERB_DEFAULT_NOARG(verb_show_status, "status", "Show current locale settings");
static int verb_show_status(int argc, char *argv[], uintptr_t _data, void *userdata) {
_cleanup_(status_info_clear) StatusInfo info = {};
static const struct bus_properties_map map[] = {
+1 -2
View File
@@ -269,8 +269,7 @@ static int list_sessions_table_add_fallback(Table *table, sd_bus_message *reply,
VERB_GROUP("Session Commands");
VERB(verb_list_sessions, "list-sessions", NULL, VERB_ANY, 1, VERB_DEFAULT,
"List sessions");
VERB_DEFAULT_NOARG(verb_list_sessions, "list-sessions", "List sessions");
static int verb_list_sessions(int argc, char *argv[], uintptr_t _data, void *userdata) {
sd_bus *bus = ASSERT_PTR(userdata);
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+1215 -1330
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -416,8 +416,7 @@ static int validate_stub(void) {
return 0;
}
VERB(verb_status, "status", NULL, VERB_ANY, 1, VERB_DEFAULT,
"Show current PCR values");
VERB_DEFAULT_NOARG(verb_status, "status", "Show current PCR values");
static int verb_status(int argc, char *argv[], uintptr_t _data, void *userdata) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
int r;
+1 -2
View File
@@ -65,8 +65,7 @@ static int help(void) {
VERB_COMMON_HELP_HIDDEN(help);
VERB(verb_dump_state, "dump", NULL, VERB_ANY, 1, VERB_DEFAULT,
"Output the current state of systemd-oomd");
VERB_DEFAULT_NOARG(verb_dump_state, "dump", "Output the current state of systemd-oomd");
static int verb_dump_state(int argc, char *argv[], uintptr_t _data, void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
+1 -1
View File
@@ -2500,7 +2500,7 @@ static int event_log_load_and_process(EventLog **ret) {
return 0;
}
VERB(verb_show_log, "log", NULL, VERB_ANY, 1, VERB_DEFAULT,
VERB_DEFAULT_NOARG(verb_show_log, "log",
"Show measurement log");
static int verb_show_log(int argc, char *argv[], uintptr_t _data, void *userdata) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *log_table = NULL, *pcr_table = NULL;
+1 -1
View File
@@ -253,7 +253,7 @@ static int maybe_reload(sd_bus **bus) {
return bus_service_manager_reload(*bus);
}
VERB(verb_list_images, "list", NULL, VERB_ANY, 1, VERB_DEFAULT,
VERB_DEFAULT_NOARG(verb_list_images, "list",
"List available portable service images (default)");
static int verb_list_images(int argc, char *argv[], uintptr_t _data, void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+2
View File
@@ -60,6 +60,8 @@ typedef struct {
VERB_SCOPE(scope, d, v, /* a= */ NULL, /* amin= */ VERB_ANY, /* amax= */ 1, /* f= */ 0, h)
#define VERB_NOARG(d, v, h) \
VERB_SCOPE_NOARG(static, d, v, h)
#define VERB_DEFAULT_NOARG(d, v, h) \
VERB_SCOPE(static, d, v, /* a= */ NULL, /* amin= */ VERB_ANY, /* amax= */ 1, /* f= */ VERB_DEFAULT, h)
/* Magic entry in the table (which will not be returned) that designates the start of the group <gr>.
* The macro works as a separator between groups and must be between other VERB* stanzas. */
+1 -1
View File
@@ -2305,7 +2305,7 @@ static int merge(ImageClass image_class,
return 1;
}
VERB(verb_status, "status", NULL, VERB_ANY, 1, VERB_DEFAULT, "Show current merge status (default)");
VERB_DEFAULT_NOARG(verb_status, "status", "Show current merge status (default)");
static int verb_status(int argc, char *argv[], uintptr_t _data, void *userdata) {
_cleanup_(table_unrefp) Table *t = NULL;
int r, ret = 0;
+1 -1
View File
@@ -180,7 +180,7 @@ static int print_status_info(const StatusInfo *i) {
return 0;
}
VERB(verb_status, "status", NULL, VERB_ANY, 1, VERB_DEFAULT, "Show current time settings");
VERB_DEFAULT_NOARG(verb_status, "status", "Show current time settings");
static int verb_status(int argc, char *argv[], uintptr_t _data, void *userdata) {
StatusInfo info = {};
static const struct bus_properties_map map[] = {
+1
View File
@@ -120,6 +120,7 @@ machinectl disable long-running long-running long-running container1
[[ "$(TERM=dumb machinectl shell testuser@ /usr/bin/bash -c 'echo -ne $FOO')" == "" ]]
[[ "$(TERM=dumb machinectl shell --setenv=FOO=bar testuser@ /usr/bin/bash -c 'echo -ne $FOO')" == "bar" ]]
[[ "$(TERM=dumb machinectl shell testuser@ --setenv=FOO=bar /usr/bin/bash -c 'echo -ne $FOO')" == "bar" ]]
[[ "$(machinectl show --property=State --value long-running)" == "running" ]]
# Equivalent to machinectl kill --signal=SIGRTMIN+4 --kill-whom=leader