From 32baf64d5ad131a1480a1ff9b3d47e32a33bc9d5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 21 Feb 2022 16:30:45 +0100 Subject: [PATCH 1/2] systemctl: systematically rename verb entrypoints verb_xyz() Let's clean up our function naming a bit, and always name the verb_xyz(), where the xyz maps to the command line verb as closely as possible. No actual code changes, just an attempt to make the systemctl sources a bit more systematic, and less surprising. --- src/systemctl/systemctl-add-dependency.c | 4 +- src/systemctl/systemctl-add-dependency.h | 2 +- src/systemctl/systemctl-cancel-job.c | 4 +- src/systemctl/systemctl-cancel-job.h | 2 +- src/systemctl/systemctl-clean-or-freeze.c | 2 +- src/systemctl/systemctl-clean-or-freeze.h | 2 +- src/systemctl/systemctl-compat-telinit.c | 4 +- src/systemctl/systemctl-daemon-reload.c | 2 +- src/systemctl/systemctl-daemon-reload.h | 2 +- src/systemctl/systemctl-edit.c | 6 +- src/systemctl/systemctl-edit.h | 4 +- src/systemctl/systemctl-enable.c | 8 +- src/systemctl/systemctl-enable.h | 2 +- src/systemctl/systemctl-is-active.c | 4 +- src/systemctl/systemctl-is-active.h | 4 +- src/systemctl/systemctl-is-enabled.c | 2 +- src/systemctl/systemctl-is-enabled.h | 2 +- src/systemctl/systemctl-is-system-running.c | 2 +- src/systemctl/systemctl-is-system-running.h | 2 +- src/systemctl/systemctl-kill.c | 2 +- src/systemctl/systemctl-kill.h | 2 +- src/systemctl/systemctl-list-dependencies.c | 2 +- src/systemctl/systemctl-list-dependencies.h | 2 +- src/systemctl/systemctl-list-jobs.c | 2 +- src/systemctl/systemctl-list-jobs.h | 2 +- src/systemctl/systemctl-list-machines.c | 2 +- src/systemctl/systemctl-list-machines.h | 2 +- src/systemctl/systemctl-list-unit-files.c | 2 +- src/systemctl/systemctl-list-unit-files.h | 2 +- src/systemctl/systemctl-list-units.c | 6 +- src/systemctl/systemctl-list-units.h | 6 +- src/systemctl/systemctl-log-setting.c | 4 +- src/systemctl/systemctl-log-setting.h | 4 +- src/systemctl/systemctl-mount.c | 4 +- src/systemctl/systemctl-mount.h | 4 +- src/systemctl/systemctl-preset-all.c | 4 +- src/systemctl/systemctl-preset-all.h | 2 +- src/systemctl/systemctl-reset-failed.c | 4 +- src/systemctl/systemctl-reset-failed.h | 2 +- src/systemctl/systemctl-service-watchdogs.c | 2 +- src/systemctl/systemctl-service-watchdogs.h | 2 +- src/systemctl/systemctl-set-default.c | 6 +- src/systemctl/systemctl-set-default.h | 4 +- src/systemctl/systemctl-set-environment.c | 6 +- src/systemctl/systemctl-set-environment.h | 6 +- src/systemctl/systemctl-set-property.c | 2 +- src/systemctl/systemctl-set-property.h | 2 +- src/systemctl/systemctl-show.c | 2 +- src/systemctl/systemctl-show.h | 2 +- src/systemctl/systemctl-start-special.c | 10 +- src/systemctl/systemctl-start-special.h | 4 +- src/systemctl/systemctl-start-unit.c | 2 +- src/systemctl/systemctl-start-unit.h | 2 +- src/systemctl/systemctl-switch-root.c | 2 +- src/systemctl/systemctl-switch-root.h | 2 +- src/systemctl/systemctl-trivial-method.c | 2 +- src/systemctl/systemctl-trivial-method.h | 2 +- src/systemctl/systemctl.c | 154 ++++++++++---------- 58 files changed, 167 insertions(+), 167 deletions(-) diff --git a/src/systemctl/systemctl-add-dependency.c b/src/systemctl/systemctl-add-dependency.c index ba385ea2a2..9276ed3e2b 100644 --- a/src/systemctl/systemctl-add-dependency.c +++ b/src/systemctl/systemctl-add-dependency.c @@ -7,7 +7,7 @@ #include "systemctl-util.h" #include "systemctl.h" -int add_dependency(int argc, char *argv[], void *userdata) { +int verb_add_dependency(int argc, char *argv[], void *userdata) { _cleanup_strv_free_ char **names = NULL; _cleanup_free_ char *target = NULL; const char *verb = argv[0]; @@ -78,7 +78,7 @@ int add_dependency(int argc, char *argv[], void *userdata) { goto finish; } - r = daemon_reload(argc, argv, userdata); + r = verb_daemon_reload(argc, argv, userdata); } finish: diff --git a/src/systemctl/systemctl-add-dependency.h b/src/systemctl/systemctl-add-dependency.h index deb0da4f30..11e5c82cc9 100644 --- a/src/systemctl/systemctl-add-dependency.h +++ b/src/systemctl/systemctl-add-dependency.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int add_dependency(int argc, char *argv[], void *userdata); +int verb_add_dependency(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-cancel-job.c b/src/systemctl/systemctl-cancel-job.c index 4c5203c1f9..76976010ad 100644 --- a/src/systemctl/systemctl-cancel-job.c +++ b/src/systemctl/systemctl-cancel-job.c @@ -8,13 +8,13 @@ #include "systemctl-util.h" #include "systemctl.h" -int cancel_job(int argc, char *argv[], void *userdata) { +int verb_cancel(int argc, char *argv[], void *userdata) { sd_bus *bus; char **name; int r; if (argc <= 1) /* Shortcut to trivial_method() if no argument is given */ - return trivial_method(argc, argv, userdata); + return verb_trivial_method(argc, argv, userdata); r = acquire_bus(BUS_MANAGER, &bus); if (r < 0) diff --git a/src/systemctl/systemctl-cancel-job.h b/src/systemctl/systemctl-cancel-job.h index 75151d67fc..397e5155f3 100644 --- a/src/systemctl/systemctl-cancel-job.h +++ b/src/systemctl/systemctl-cancel-job.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int cancel_job(int argc, char *argv[], void *userdata); +int verb_cancel(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-clean-or-freeze.c b/src/systemctl/systemctl-clean-or-freeze.c index fb4d643517..7ed41e8e0a 100644 --- a/src/systemctl/systemctl-clean-or-freeze.c +++ b/src/systemctl/systemctl-clean-or-freeze.c @@ -7,7 +7,7 @@ #include "systemctl-util.h" #include "systemctl.h" -int clean_or_freeze_unit(int argc, char *argv[], void *userdata) { +int verb_clean_or_freeze(int argc, char *argv[], void *userdata) { _cleanup_(bus_wait_for_units_freep) BusWaitForUnits *w = NULL; _cleanup_strv_free_ char **names = NULL; int r, ret = EXIT_SUCCESS; diff --git a/src/systemctl/systemctl-clean-or-freeze.h b/src/systemctl/systemctl-clean-or-freeze.h index 8e73f4efbe..5f2bca4a4e 100644 --- a/src/systemctl/systemctl-clean-or-freeze.h +++ b/src/systemctl/systemctl-clean-or-freeze.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int clean_or_freeze_unit(int argc, char *argv[], void *userdata); +int verb_clean_or_freeze(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-compat-telinit.c b/src/systemctl/systemctl-compat-telinit.c index 0890d6544f..1e771ef4a6 100644 --- a/src/systemctl/systemctl-compat-telinit.c +++ b/src/systemctl/systemctl-compat-telinit.c @@ -128,7 +128,7 @@ int start_with_fallback(void) { int r; /* First, try systemd via D-Bus. */ - r = start_unit(0, NULL, NULL); + r = verb_start(0, NULL, NULL); if (r == 0) return 0; @@ -143,7 +143,7 @@ int start_with_fallback(void) { int reload_with_fallback(void) { /* First, try systemd via D-Bus. */ - if (daemon_reload(0, NULL, NULL) >= 0) + if (verb_daemon_reload(0, NULL, NULL) >= 0) return 0; /* Nothing else worked, so let's try signals */ diff --git a/src/systemctl/systemctl-daemon-reload.c b/src/systemctl/systemctl-daemon-reload.c index 1c23315337..35a10e84cc 100644 --- a/src/systemctl/systemctl-daemon-reload.c +++ b/src/systemctl/systemctl-daemon-reload.c @@ -6,7 +6,7 @@ #include "systemctl-util.h" #include "systemctl.h" -int daemon_reload(int argc, char *argv[], void *userdata) { +int verb_daemon_reload(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; const char *method; diff --git a/src/systemctl/systemctl-daemon-reload.h b/src/systemctl/systemctl-daemon-reload.h index a9fc00770a..d4215cc37c 100644 --- a/src/systemctl/systemctl-daemon-reload.h +++ b/src/systemctl/systemctl-daemon-reload.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int daemon_reload(int argc, char *argv[], void *userdata); +int verb_daemon_reload(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index b59a67ac22..4b19bf7015 100644 --- a/src/systemctl/systemctl-edit.c +++ b/src/systemctl/systemctl-edit.c @@ -22,7 +22,7 @@ #define EDIT_MARKER_START "### Anything between here and the comment below will become the new contents of the file" #define EDIT_MARKER_END "### Lines below this comment will be discarded" -int cat(int argc, char *argv[], void *userdata) { +int verb_cat(int argc, char *argv[], void *userdata) { _cleanup_(hashmap_freep) Hashmap *cached_name_map = NULL, *cached_id_map = NULL; _cleanup_(lookup_paths_free) LookupPaths lp = {}; _cleanup_strv_free_ char **names = NULL; @@ -497,7 +497,7 @@ static int trim_edit_markers(const char *path) { return 0; } -int edit(int argc, char *argv[], void *userdata) { +int verb_edit(int argc, char *argv[], void *userdata) { _cleanup_(lookup_paths_free) LookupPaths lp = {}; _cleanup_strv_free_ char **names = NULL; _cleanup_strv_free_ char **paths = NULL; @@ -570,7 +570,7 @@ int edit(int argc, char *argv[], void *userdata) { r = 0; if (!arg_no_reload && !install_client_side()) - r = daemon_reload(argc, argv, userdata); + r = verb_daemon_reload(argc, argv, userdata); end: STRV_FOREACH_PAIR(original, tmp, paths) { diff --git a/src/systemctl/systemctl-edit.h b/src/systemctl/systemctl-edit.h index fe7e4dc757..10dac5cb2a 100644 --- a/src/systemctl/systemctl-edit.h +++ b/src/systemctl/systemctl-edit.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int cat(int argc, char *argv[], void *userdata); -int edit(int argc, char *argv[], void *userdata); +int verb_cat(int argc, char *argv[], void *userdata); +int verb_edit(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-enable.c b/src/systemctl/systemctl-enable.c index dcbe2c7302..f258d9643b 100644 --- a/src/systemctl/systemctl-enable.c +++ b/src/systemctl/systemctl-enable.c @@ -62,7 +62,7 @@ static int normalize_names(char **names, bool warn_if_path) { return 0; } -int enable_unit(int argc, char *argv[], void *userdata) { +int verb_enable(int argc, char *argv[], void *userdata) { _cleanup_strv_free_ char **names = NULL; const char *verb = argv[0]; UnitFileChange *changes = NULL; @@ -86,7 +86,7 @@ int enable_unit(int argc, char *argv[], void *userdata) { if (strv_isempty(names)) { if (arg_no_reload || install_client_side()) return 0; - return daemon_reload(argc, argv, userdata); + return verb_daemon_reload(argc, argv, userdata); } if (streq(verb, "disable")) { @@ -235,7 +235,7 @@ int enable_unit(int argc, char *argv[], void *userdata) { /* Try to reload if enabled */ if (!arg_no_reload) - r = daemon_reload(argc, argv, userdata); + r = verb_daemon_reload(argc, argv, userdata); else r = 0; } @@ -273,7 +273,7 @@ int enable_unit(int argc, char *argv[], void *userdata) { new_args[i + 1] = basename(names[i]); new_args[i + 1] = NULL; - r = start_unit(len + 1, new_args, userdata); + r = verb_start(len + 1, new_args, userdata); } } diff --git a/src/systemctl/systemctl-enable.h b/src/systemctl/systemctl-enable.h index 43f60e78e3..f04bbcd62a 100644 --- a/src/systemctl/systemctl-enable.h +++ b/src/systemctl/systemctl-enable.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int enable_unit(int argc, char *argv[], void *userdata); +int verb_enable(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-is-active.c b/src/systemctl/systemctl-is-active.c index d83736e94a..e1acf79702 100644 --- a/src/systemctl/systemctl-is-active.c +++ b/src/systemctl/systemctl-is-active.c @@ -43,7 +43,7 @@ static int check_unit_generic(int code, const UnitActiveState good_states[], int return found ? 0 : code; } -int check_unit_active(int argc, char *argv[], void *userdata) { +int verb_is_active(int argc, char *argv[], void *userdata) { static const UnitActiveState states[] = { UNIT_ACTIVE, UNIT_RELOADING, @@ -53,7 +53,7 @@ int check_unit_active(int argc, char *argv[], void *userdata) { return check_unit_generic(EXIT_PROGRAM_NOT_RUNNING, states, ELEMENTSOF(states), strv_skip(argv, 1)); } -int check_unit_failed(int argc, char *argv[], void *userdata) { +int verb_is_failed(int argc, char *argv[], void *userdata) { static const UnitActiveState states[] = { UNIT_FAILED, }; diff --git a/src/systemctl/systemctl-is-active.h b/src/systemctl/systemctl-is-active.h index 9a5238e8c0..950f29ac55 100644 --- a/src/systemctl/systemctl-is-active.h +++ b/src/systemctl/systemctl-is-active.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int check_unit_active(int argc, char *argv[], void *userdata); -int check_unit_failed(int argc, char *argv[], void *userdata); +int verb_is_active(int argc, char *argv[], void *userdata); +int verb_is_failed(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-is-enabled.c b/src/systemctl/systemctl-is-enabled.c index e33dffaf29..3b4fbd9c1f 100644 --- a/src/systemctl/systemctl-is-enabled.c +++ b/src/systemctl/systemctl-is-enabled.c @@ -56,7 +56,7 @@ static int show_installation_targets(sd_bus *bus, const char *name) { return 0; } -int unit_is_enabled(int argc, char *argv[], void *userdata) { +int verb_is_enabled(int argc, char *argv[], void *userdata) { _cleanup_strv_free_ char **names = NULL; bool enabled; char **name; diff --git a/src/systemctl/systemctl-is-enabled.h b/src/systemctl/systemctl-is-enabled.h index 5cb9e5c537..96dff95d6f 100644 --- a/src/systemctl/systemctl-is-enabled.h +++ b/src/systemctl/systemctl-is-enabled.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int unit_is_enabled(int argc, char *argv[], void *userdata); +int verb_is_enabled(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-is-system-running.c b/src/systemctl/systemctl-is-system-running.c index ecebf0d114..ea89eb2cc7 100644 --- a/src/systemctl/systemctl-is-system-running.c +++ b/src/systemctl/systemctl-is-system-running.c @@ -23,7 +23,7 @@ static int match_startup_finished(sd_bus_message *m, void *userdata, sd_bus_erro return 0; } -int is_system_running(int argc, char *argv[], void *userdata) { +int verb_is_system_running(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_slot_unrefp) sd_bus_slot *slot_startup_finished = NULL; _cleanup_(sd_event_unrefp) sd_event* event = NULL; diff --git a/src/systemctl/systemctl-is-system-running.h b/src/systemctl/systemctl-is-system-running.h index 3d7e9fb83d..de86211a91 100644 --- a/src/systemctl/systemctl-is-system-running.h +++ b/src/systemctl/systemctl-is-system-running.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int is_system_running(int argc, char *argv[], void *userdata); +int verb_is_system_running(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-kill.c b/src/systemctl/systemctl-kill.c index 489e754752..0346be98a6 100644 --- a/src/systemctl/systemctl-kill.c +++ b/src/systemctl/systemctl-kill.c @@ -6,7 +6,7 @@ #include "systemctl-util.h" #include "systemctl.h" -int kill_unit(int argc, char *argv[], void *userdata) { +int verb_kill(int argc, char *argv[], void *userdata) { _cleanup_strv_free_ char **names = NULL; char *kill_who = NULL, **name; sd_bus *bus; diff --git a/src/systemctl/systemctl-kill.h b/src/systemctl/systemctl-kill.h index a42d4f1f90..88b2eae4b2 100644 --- a/src/systemctl/systemctl-kill.h +++ b/src/systemctl/systemctl-kill.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int kill_unit(int argc, char *argv[], void *userdata); +int verb_kill(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-list-dependencies.c b/src/systemctl/systemctl-list-dependencies.c index a536240a9f..0a45a017e6 100644 --- a/src/systemctl/systemctl-list-dependencies.c +++ b/src/systemctl/systemctl-list-dependencies.c @@ -136,7 +136,7 @@ static int list_dependencies_one( return 0; } -int list_dependencies(int argc, char *argv[], void *userdata) { +int verb_list_dependencies(int argc, char *argv[], void *userdata) { _cleanup_strv_free_ char **units = NULL, **done = NULL; char **u, **patterns; sd_bus *bus; diff --git a/src/systemctl/systemctl-list-dependencies.h b/src/systemctl/systemctl-list-dependencies.h index 7246570144..1e68a5f9f0 100644 --- a/src/systemctl/systemctl-list-dependencies.h +++ b/src/systemctl/systemctl-list-dependencies.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int list_dependencies(int argc, char *argv[], void *userdata); +int verb_list_dependencies(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-list-jobs.c b/src/systemctl/systemctl-list-jobs.c index 1a39416d39..f9eba23683 100644 --- a/src/systemctl/systemctl-list-jobs.c +++ b/src/systemctl/systemctl-list-jobs.c @@ -125,7 +125,7 @@ static bool output_show_job(struct job_info *job, char **patterns) { return strv_fnmatch_or_empty(patterns, job->name, FNM_NOESCAPE); } -int list_jobs(int argc, char *argv[], void *userdata) { +int verb_list_jobs(int argc, char *argv[], 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; _cleanup_free_ struct job_info *jobs = NULL; diff --git a/src/systemctl/systemctl-list-jobs.h b/src/systemctl/systemctl-list-jobs.h index aa49696394..b10ec79b3e 100644 --- a/src/systemctl/systemctl-list-jobs.h +++ b/src/systemctl/systemctl-list-jobs.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int list_jobs(int argc, char *argv[], void *userdata); +int verb_list_jobs(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-list-machines.c b/src/systemctl/systemctl-list-machines.c index b4eb0bd4b6..1ebfb019ec 100644 --- a/src/systemctl/systemctl-list-machines.c +++ b/src/systemctl/systemctl-list-machines.c @@ -219,7 +219,7 @@ static int output_machines_list(struct machine_info *machine_infos, unsigned n) return 0; } -int list_machines(int argc, char *argv[], void *userdata) { +int verb_list_machines(int argc, char *argv[], void *userdata) { struct machine_info *machine_infos = NULL; sd_bus *bus; int r, rc; diff --git a/src/systemctl/systemctl-list-machines.h b/src/systemctl/systemctl-list-machines.h index 4a33e2b27c..9dff0d1728 100644 --- a/src/systemctl/systemctl-list-machines.h +++ b/src/systemctl/systemctl-list-machines.h @@ -7,7 +7,7 @@ #include "bus-map-properties.h" #include "time-util.h" -int list_machines(int argc, char *argv[], void *userdata); +int verb_list_machines(int argc, char *argv[], void *userdata); struct machine_info { bool is_host; diff --git a/src/systemctl/systemctl-list-unit-files.c b/src/systemctl/systemctl-list-unit-files.c index a729171ded..08f4bd7e2a 100644 --- a/src/systemctl/systemctl-list-unit-files.c +++ b/src/systemctl/systemctl-list-unit-files.c @@ -133,7 +133,7 @@ static int output_unit_file_list(const UnitFileList *units, unsigned c) { return 0; } -int list_unit_files(int argc, char *argv[], void *userdata) { +int verb_list_unit_files(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; _cleanup_free_ UnitFileList *units = NULL; unsigned c = 0; diff --git a/src/systemctl/systemctl-list-unit-files.h b/src/systemctl/systemctl-list-unit-files.h index 387233e01c..4819fbd820 100644 --- a/src/systemctl/systemctl-list-unit-files.h +++ b/src/systemctl/systemctl-list-unit-files.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int list_unit_files(int argc, char *argv[], void *userdata); +int verb_list_unit_files(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-list-units.c b/src/systemctl/systemctl-list-units.c index 0c405fb7e8..fdf524385f 100644 --- a/src/systemctl/systemctl-list-units.c +++ b/src/systemctl/systemctl-list-units.c @@ -210,7 +210,7 @@ static int output_units_list(const UnitInfo *unit_infos, unsigned c) { return 0; } -int list_units(int argc, char *argv[], void *userdata) { +int verb_list_units(int argc, char *argv[], void *userdata) { _cleanup_free_ UnitInfo *unit_infos = NULL; _cleanup_(message_set_freep) Set *replies = NULL; _cleanup_strv_free_ char **machines = NULL; @@ -425,7 +425,7 @@ static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) { return 0; } -int list_sockets(int argc, char *argv[], void *userdata) { +int verb_list_sockets(int argc, char *argv[], void *userdata) { _cleanup_(message_set_freep) Set *replies = NULL; _cleanup_strv_free_ char **machines = NULL; _cleanup_strv_free_ char **sockets_with_suffix = NULL; @@ -688,7 +688,7 @@ usec_t calc_next_elapse(dual_timestamp *nw, dual_timestamp *next) { return next_elapse; } -int list_timers(int argc, char *argv[], void *userdata) { +int verb_list_timers(int argc, char *argv[], void *userdata) { _cleanup_(message_set_freep) Set *replies = NULL; _cleanup_strv_free_ char **machines = NULL; _cleanup_strv_free_ char **timers_with_suffix = NULL; diff --git a/src/systemctl/systemctl-list-units.h b/src/systemctl/systemctl-list-units.h index ef27627712..7f4cee0d10 100644 --- a/src/systemctl/systemctl-list-units.h +++ b/src/systemctl/systemctl-list-units.h @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int list_units(int argc, char *argv[], void *userdata); -int list_sockets(int argc, char *argv[], void *userdata); -int list_timers(int argc, char *argv[], void *userdata); +int verb_list_units(int argc, char *argv[], void *userdata); +int verb_list_sockets(int argc, char *argv[], void *userdata); +int verb_list_timers(int argc, char *argv[], void *userdata); usec_t calc_next_elapse(dual_timestamp *nw, dual_timestamp *next); diff --git a/src/systemctl/systemctl-log-setting.c b/src/systemctl/systemctl-log-setting.c index e3e9576471..88b2e49b1a 100644 --- a/src/systemctl/systemctl-log-setting.c +++ b/src/systemctl/systemctl-log-setting.c @@ -21,7 +21,7 @@ static void give_log_control1_hint(const char *name) { " See the %s for details.", link ?: "org.freedesktop.LogControl1(5) man page"); } -int log_setting(int argc, char *argv[], void *userdata) { +int verb_log_setting(int argc, char *argv[], void *userdata) { sd_bus *bus; int r; @@ -66,7 +66,7 @@ static int service_name_to_dbus(sd_bus *bus, const char *name, char **ret_dbus_n return 0; } -int service_log_setting(int argc, char *argv[], void *userdata) { +int verb_service_log_setting(int argc, char *argv[], void *userdata) { sd_bus *bus; _cleanup_free_ char *unit = NULL, *dbus_name = NULL; int r; diff --git a/src/systemctl/systemctl-log-setting.h b/src/systemctl/systemctl-log-setting.h index 9a2e793f03..910d6c8af5 100644 --- a/src/systemctl/systemctl-log-setting.h +++ b/src/systemctl/systemctl-log-setting.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int log_setting(int argc, char *argv[], void *userdata); -int service_log_setting(int argc, char *argv[], void *userdata); +int verb_log_setting(int argc, char *argv[], void *userdata); +int verb_service_log_setting(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-mount.c b/src/systemctl/systemctl-mount.c index 04e626550d..d9ad332b2f 100644 --- a/src/systemctl/systemctl-mount.c +++ b/src/systemctl/systemctl-mount.c @@ -7,7 +7,7 @@ #include "systemctl-util.h" #include "systemctl.h" -int mount_bind(int argc, char *argv[], void *userdata) { +int verb_bind(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_free_ char *n = NULL; sd_bus *bus; @@ -41,7 +41,7 @@ int mount_bind(int argc, char *argv[], void *userdata) { return 0; } -int mount_image(int argc, char *argv[], void *userdata) { +int verb_mount_image(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; const char *unit = argv[1], *src = argv[2], *dest = argv[3]; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; diff --git a/src/systemctl/systemctl-mount.h b/src/systemctl/systemctl-mount.h index 60d6875d82..b2d0750016 100644 --- a/src/systemctl/systemctl-mount.h +++ b/src/systemctl/systemctl-mount.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int mount_bind(int argc, char *argv[], void *userdata); -int mount_image(int argc, char *argv[], void *userdata); +int verb_bind(int argc, char *argv[], void *userdata); +int verb_mount_image(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-preset-all.c b/src/systemctl/systemctl-preset-all.c index b5eb199f4a..fa98a9bf80 100644 --- a/src/systemctl/systemctl-preset-all.c +++ b/src/systemctl/systemctl-preset-all.c @@ -7,7 +7,7 @@ #include "systemctl-util.h" #include "systemctl.h" -int preset_all(int argc, char *argv[], void *userdata) { +int verb_preset_all(int argc, char *argv[], void *userdata) { UnitFileChange *changes = NULL; size_t n_changes = 0; int r; @@ -51,7 +51,7 @@ int preset_all(int argc, char *argv[], void *userdata) { goto finish; } - r = daemon_reload(argc, argv, userdata); + r = verb_daemon_reload(argc, argv, userdata); } finish: diff --git a/src/systemctl/systemctl-preset-all.h b/src/systemctl/systemctl-preset-all.h index f4f6790404..4631e7ea31 100644 --- a/src/systemctl/systemctl-preset-all.h +++ b/src/systemctl/systemctl-preset-all.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int preset_all(int argc, char *argv[], void *userdata); +int verb_preset_all(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-reset-failed.c b/src/systemctl/systemctl-reset-failed.c index eee7586465..abc8aadf63 100644 --- a/src/systemctl/systemctl-reset-failed.c +++ b/src/systemctl/systemctl-reset-failed.c @@ -7,14 +7,14 @@ #include "systemctl-util.h" #include "systemctl.h" -int reset_failed(int argc, char *argv[], void *userdata) { +int verb_reset_failed(int argc, char *argv[], void *userdata) { _cleanup_strv_free_ char **names = NULL; sd_bus *bus; char **name; int r, q; if (argc <= 1) /* Shortcut to trivial_method() if no argument is given */ - return trivial_method(argc, argv, userdata); + return verb_trivial_method(argc, argv, userdata); r = acquire_bus(BUS_MANAGER, &bus); if (r < 0) diff --git a/src/systemctl/systemctl-reset-failed.h b/src/systemctl/systemctl-reset-failed.h index 956bb469df..5da0659d6e 100644 --- a/src/systemctl/systemctl-reset-failed.h +++ b/src/systemctl/systemctl-reset-failed.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int reset_failed(int argc, char *argv[], void *userdata); +int verb_reset_failed(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-service-watchdogs.c b/src/systemctl/systemctl-service-watchdogs.c index e579851097..620f46aafb 100644 --- a/src/systemctl/systemctl-service-watchdogs.c +++ b/src/systemctl/systemctl-service-watchdogs.c @@ -7,7 +7,7 @@ #include "systemctl-util.h" #include "systemctl.h" -int service_watchdogs(int argc, char *argv[], void *userdata) { +int verb_service_watchdogs(int argc, char *argv[], void *userdata) { sd_bus *bus; _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; int b, r; diff --git a/src/systemctl/systemctl-service-watchdogs.h b/src/systemctl/systemctl-service-watchdogs.h index 11a53dbbf1..2f59f5a3f4 100644 --- a/src/systemctl/systemctl-service-watchdogs.h +++ b/src/systemctl/systemctl-service-watchdogs.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int service_watchdogs(int argc, char *argv[], void *userdata); +int verb_service_watchdogs(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-set-default.c b/src/systemctl/systemctl-set-default.c index 05c1894b1d..db149e78cf 100644 --- a/src/systemctl/systemctl-set-default.c +++ b/src/systemctl/systemctl-set-default.c @@ -76,7 +76,7 @@ static int determine_default(char **ret_name) { } } -int get_default(int argc, char *argv[], void *userdata) { +int verb_get_default(int argc, char *argv[], void *userdata) { _cleanup_free_ char *name = NULL; int r; @@ -91,7 +91,7 @@ int get_default(int argc, char *argv[], void *userdata) { return 0; } -int set_default(int argc, char *argv[], void *userdata) { +int verb_set_default(int argc, char *argv[], void *userdata) { _cleanup_free_ char *unit = NULL; UnitFileChange *changes = NULL; size_t n_changes = 0; @@ -133,7 +133,7 @@ int set_default(int argc, char *argv[], void *userdata) { /* Try to reload if enabled */ if (!arg_no_reload) - r = daemon_reload(argc, argv, userdata); + r = verb_daemon_reload(argc, argv, userdata); else r = 0; } diff --git a/src/systemctl/systemctl-set-default.h b/src/systemctl/systemctl-set-default.h index 839b2c9b9f..7873e12678 100644 --- a/src/systemctl/systemctl-set-default.h +++ b/src/systemctl/systemctl-set-default.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int get_default(int argc, char *argv[], void *userdata); -int set_default(int argc, char *argv[], void *userdata); +int verb_get_default(int argc, char *argv[], void *userdata); +int verb_set_default(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-set-environment.c b/src/systemctl/systemctl-set-environment.c index 9d6a37b206..61540e03e2 100644 --- a/src/systemctl/systemctl-set-environment.c +++ b/src/systemctl/systemctl-set-environment.c @@ -59,7 +59,7 @@ static int print_variable(const char *s) { return 0; } -int show_environment(int argc, char *argv[], void *userdata) { +int verb_show_environment(int argc, char *argv[], 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; const char *text; @@ -111,7 +111,7 @@ static void invalid_callback(const char *p, void *userdata) { log_debug("Ignoring invalid environment assignment \"%s\".", strnull(t)); } -int set_environment(int argc, char *argv[], void *userdata) { +int verb_set_environment(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; const char *method; @@ -146,7 +146,7 @@ int set_environment(int argc, char *argv[], void *userdata) { return 0; } -int import_environment(int argc, char *argv[], void *userdata) { +int verb_import_environment(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; sd_bus *bus; diff --git a/src/systemctl/systemctl-set-environment.h b/src/systemctl/systemctl-set-environment.h index bd05e318ad..404258aa43 100644 --- a/src/systemctl/systemctl-set-environment.h +++ b/src/systemctl/systemctl-set-environment.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int show_environment(int argc, char *argv[], void *userdata); -int set_environment(int argc, char *argv[], void *userdata); -int import_environment(int argc, char *argv[], void *userdata); +int verb_show_environment(int argc, char *argv[], void *userdata); +int verb_set_environment(int argc, char *argv[], void *userdata); +int verb_import_environment(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-set-property.c b/src/systemctl/systemctl-set-property.c index 5739bac070..24182d4fff 100644 --- a/src/systemctl/systemctl-set-property.c +++ b/src/systemctl/systemctl-set-property.c @@ -43,7 +43,7 @@ static int set_property_one(sd_bus *bus, const char *name, char **properties) { return 0; } -int set_property(int argc, char *argv[], void *userdata) { +int verb_set_property(int argc, char *argv[], void *userdata) { sd_bus *bus; _cleanup_strv_free_ char **names = NULL; char **name; diff --git a/src/systemctl/systemctl-set-property.h b/src/systemctl/systemctl-set-property.h index 74990e7cba..0892291d59 100644 --- a/src/systemctl/systemctl-set-property.h +++ b/src/systemctl/systemctl-set-property.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int set_property(int argc, char *argv[], void *userdata); +int verb_set_property(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index dca6d6f4c4..86a731f637 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -2146,7 +2146,7 @@ static int show_system_status(sd_bus *bus) { return 0; } -int show(int argc, char *argv[], void *userdata) { +int verb_show(int argc, char *argv[], void *userdata) { bool new_line = false, ellipsized = false; SystemctlShowMode show_mode; int r, ret = 0; diff --git a/src/systemctl/systemctl-show.h b/src/systemctl/systemctl-show.h index d778bebb43..5aeed51e5b 100644 --- a/src/systemctl/systemctl-show.h +++ b/src/systemctl/systemctl-show.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int show(int argc, char *argv[], void *userdata); +int verb_show(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-start-special.c b/src/systemctl/systemctl-start-special.c index 08eefc473e..da2336d3a2 100644 --- a/src/systemctl/systemctl-start-special.c +++ b/src/systemctl/systemctl-start-special.c @@ -116,7 +116,7 @@ static int set_exit_code(uint8_t code) { return 0; } -int start_special(int argc, char *argv[], void *userdata) { +int verb_start_special(int argc, char *argv[], void *userdata) { bool termination_action; /* An action that terminates the manager, can be performed also by * signal. */ enum action a; @@ -197,7 +197,7 @@ int start_special(int argc, char *argv[], void *userdata) { if (arg_force >= 1 && (termination_action || IN_SET(a, ACTION_KEXEC, ACTION_EXIT))) - r = trivial_method(argc, argv, userdata); + r = verb_trivial_method(argc, argv, userdata); else { /* First try logind, to allow authentication with polkit */ if (IN_SET(a, @@ -229,7 +229,7 @@ int start_special(int argc, char *argv[], void *userdata) { * behaviour. */ arg_no_block = true; - r = start_unit(argc, argv, userdata); + r = verb_start(argc, argv, userdata); } if (termination_action && arg_force < 2 && @@ -239,7 +239,7 @@ int start_special(int argc, char *argv[], void *userdata) { return r; } -int start_system_special(int argc, char *argv[], void *userdata) { +int verb_start_system_special(int argc, char *argv[], void *userdata) { /* Like start_special above, but raises an error when running in user mode */ if (arg_scope != UNIT_FILE_SYSTEM) @@ -247,5 +247,5 @@ int start_system_special(int argc, char *argv[], void *userdata) { "Bad action for %s mode.", arg_scope == UNIT_FILE_GLOBAL ? "--global" : "--user"); - return start_special(argc, argv, userdata); + return verb_start_special(argc, argv, userdata); } diff --git a/src/systemctl/systemctl-start-special.h b/src/systemctl/systemctl-start-special.h index 06875e9c63..9396321d70 100644 --- a/src/systemctl/systemctl-start-special.h +++ b/src/systemctl/systemctl-start-special.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int start_special(int argc, char *argv[], void *userdata); -int start_system_special(int argc, char *argv[], void *userdata); +int verb_start_special(int argc, char *argv[], void *userdata); +int verb_start_system_special(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-start-unit.c b/src/systemctl/systemctl-start-unit.c index 274b278d2d..590ee17194 100644 --- a/src/systemctl/systemctl-start-unit.c +++ b/src/systemctl/systemctl-start-unit.c @@ -261,7 +261,7 @@ static const char** make_extra_args(const char *extra_args[static 4]) { return extra_args; } -int start_unit(int argc, char *argv[], void *userdata) { +int verb_start(int argc, char *argv[], void *userdata) { _cleanup_(bus_wait_for_units_freep) BusWaitForUnits *wu = NULL; _cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL; const char *method, *job_type, *mode, *one_name, *suffix = NULL; diff --git a/src/systemctl/systemctl-start-unit.h b/src/systemctl/systemctl-start-unit.h index 915c6fa7fb..2865016773 100644 --- a/src/systemctl/systemctl-start-unit.h +++ b/src/systemctl/systemctl-start-unit.h @@ -3,7 +3,7 @@ #include "systemctl.h" -int start_unit(int argc, char *argv[], void *userdata); +int verb_start(int argc, char *argv[], void *userdata); struct action_metadata { const char *target; diff --git a/src/systemctl/systemctl-switch-root.c b/src/systemctl/systemctl-switch-root.c index b801267974..669fa60dfd 100644 --- a/src/systemctl/systemctl-switch-root.c +++ b/src/systemctl/systemctl-switch-root.c @@ -11,7 +11,7 @@ #include "systemctl-util.h" #include "systemctl.h" -int switch_root(int argc, char *argv[], void *userdata) { +int verb_switch_root(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_free_ char *cmdline_init = NULL; const char *root, *init; diff --git a/src/systemctl/systemctl-switch-root.h b/src/systemctl/systemctl-switch-root.h index 6e13961ab7..e9ba12baf7 100644 --- a/src/systemctl/systemctl-switch-root.h +++ b/src/systemctl/systemctl-switch-root.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int switch_root(int argc, char *argv[], void *userdata); +int verb_switch_root(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-trivial-method.c b/src/systemctl/systemctl-trivial-method.c index c0b4d489a2..5e530f3a14 100644 --- a/src/systemctl/systemctl-trivial-method.c +++ b/src/systemctl/systemctl-trivial-method.c @@ -8,7 +8,7 @@ /* A generic implementation for cases we just need to invoke a simple method call on the Manager object. */ -int trivial_method(int argc, char *argv[], void *userdata) { +int verb_trivial_method(int argc, char *argv[], void *userdata) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; const char *method; sd_bus *bus; diff --git a/src/systemctl/systemctl-trivial-method.h b/src/systemctl/systemctl-trivial-method.h index 6dcd152845..d36b4803d4 100644 --- a/src/systemctl/systemctl-trivial-method.h +++ b/src/systemctl/systemctl-trivial-method.h @@ -1,4 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -int trivial_method(int argc, char *argv[], void *userdata); +int verb_trivial_method(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 0489796a75..ec29e12e39 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -1019,83 +1019,83 @@ int systemctl_dispatch_parse_argv(int argc, char *argv[]) { #ifndef FUZZ_SYSTEMCTL_PARSE_ARGV static int systemctl_main(int argc, char *argv[]) { static const Verb verbs[] = { - { "list-units", VERB_ANY, VERB_ANY, VERB_DEFAULT|VERB_ONLINE_ONLY, list_units }, - { "list-unit-files", VERB_ANY, VERB_ANY, 0, list_unit_files }, - { "list-sockets", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, list_sockets }, - { "list-timers", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, list_timers }, - { "list-jobs", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, list_jobs }, - { "list-machines", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, list_machines }, - { "clear-jobs", VERB_ANY, 1, VERB_ONLINE_ONLY, trivial_method }, - { "cancel", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, cancel_job }, - { "start", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, - { "stop", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, - { "condstop", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, /* For compatibility with ALTLinux */ - { "reload", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, - { "restart", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, - { "try-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, - { "reload-or-restart", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, - { "reload-or-try-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, /* For compatibility with old systemctl <= 228 */ - { "try-reload-or-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, - { "force-reload", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, /* For compatibility with SysV */ - { "condreload", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, /* For compatibility with ALTLinux */ - { "condrestart", 2, VERB_ANY, VERB_ONLINE_ONLY, start_unit }, /* For compatibility with RH */ - { "isolate", 2, 2, VERB_ONLINE_ONLY, start_unit }, - { "kill", 2, VERB_ANY, VERB_ONLINE_ONLY, kill_unit }, - { "clean", 2, VERB_ANY, VERB_ONLINE_ONLY, clean_or_freeze_unit }, - { "freeze", 2, VERB_ANY, VERB_ONLINE_ONLY, clean_or_freeze_unit }, - { "thaw", 2, VERB_ANY, VERB_ONLINE_ONLY, clean_or_freeze_unit }, - { "is-active", 2, VERB_ANY, VERB_ONLINE_ONLY, check_unit_active }, - { "check", 2, VERB_ANY, VERB_ONLINE_ONLY, check_unit_active }, /* deprecated alias of is-active */ - { "is-failed", 2, VERB_ANY, VERB_ONLINE_ONLY, check_unit_failed }, - { "show", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, show }, - { "cat", 2, VERB_ANY, VERB_ONLINE_ONLY, cat }, - { "status", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, show }, - { "help", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, show }, - { "daemon-reload", VERB_ANY, 1, VERB_ONLINE_ONLY, daemon_reload }, - { "daemon-reexec", VERB_ANY, 1, VERB_ONLINE_ONLY, daemon_reload }, - { "log-level", VERB_ANY, 2, VERB_ONLINE_ONLY, log_setting }, - { "log-target", VERB_ANY, 2, VERB_ONLINE_ONLY, log_setting }, - { "service-log-level", 2, 3, VERB_ONLINE_ONLY, service_log_setting }, - { "service-log-target", 2, 3, VERB_ONLINE_ONLY, service_log_setting }, - { "service-watchdogs", VERB_ANY, 2, VERB_ONLINE_ONLY, service_watchdogs }, - { "show-environment", VERB_ANY, 1, VERB_ONLINE_ONLY, show_environment }, - { "set-environment", 2, VERB_ANY, VERB_ONLINE_ONLY, set_environment }, - { "unset-environment", 2, VERB_ANY, VERB_ONLINE_ONLY, set_environment }, - { "import-environment", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, import_environment }, - { "halt", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special }, - { "poweroff", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special }, - { "reboot", VERB_ANY, 2, VERB_ONLINE_ONLY, start_system_special }, - { "kexec", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special }, - { "suspend", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special }, - { "hibernate", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special }, - { "hybrid-sleep", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special }, - { "suspend-then-hibernate",VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special }, - { "default", VERB_ANY, 1, VERB_ONLINE_ONLY, start_special }, - { "rescue", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special }, - { "emergency", VERB_ANY, 1, VERB_ONLINE_ONLY, start_system_special }, - { "exit", VERB_ANY, 2, VERB_ONLINE_ONLY, start_special }, - { "reset-failed", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, reset_failed }, - { "enable", 2, VERB_ANY, 0, enable_unit }, - { "disable", 2, VERB_ANY, 0, enable_unit }, - { "is-enabled", 2, VERB_ANY, 0, unit_is_enabled }, - { "reenable", 2, VERB_ANY, 0, enable_unit }, - { "preset", 2, VERB_ANY, 0, enable_unit }, - { "preset-all", VERB_ANY, 1, 0, preset_all }, - { "mask", 2, VERB_ANY, 0, enable_unit }, - { "unmask", 2, VERB_ANY, 0, enable_unit }, - { "link", 2, VERB_ANY, 0, enable_unit }, - { "revert", 2, VERB_ANY, 0, enable_unit }, - { "switch-root", 2, VERB_ANY, VERB_ONLINE_ONLY, switch_root }, - { "list-dependencies", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, list_dependencies }, - { "set-default", 2, 2, 0, set_default }, - { "get-default", VERB_ANY, 1, 0, get_default }, - { "set-property", 3, VERB_ANY, VERB_ONLINE_ONLY, set_property }, - { "is-system-running", VERB_ANY, 1, 0, is_system_running }, - { "add-wants", 3, VERB_ANY, 0, add_dependency }, - { "add-requires", 3, VERB_ANY, 0, add_dependency }, - { "edit", 2, VERB_ANY, VERB_ONLINE_ONLY, edit }, - { "bind", 3, 4, VERB_ONLINE_ONLY, mount_bind }, - { "mount-image", 4, 5, VERB_ONLINE_ONLY, mount_image }, + { "list-units", VERB_ANY, VERB_ANY, VERB_DEFAULT|VERB_ONLINE_ONLY, verb_list_units }, + { "list-unit-files", VERB_ANY, VERB_ANY, 0, verb_list_unit_files }, + { "list-sockets", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_sockets }, + { "list-timers", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_timers }, + { "list-jobs", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_jobs }, + { "list-machines", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_machines }, + { "clear-jobs", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_trivial_method }, + { "cancel", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_cancel }, + { "start", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, + { "stop", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, + { "condstop", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, /* For compatibility with ALTLinux */ + { "reload", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, + { "restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, + { "try-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, + { "reload-or-restart", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, + { "reload-or-try-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, /* For compatibility with old systemctl <= 228 */ + { "try-reload-or-restart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, + { "force-reload", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, /* For compatibility with SysV */ + { "condreload", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, /* For compatibility with ALTLinux */ + { "condrestart", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_start }, /* For compatibility with RH */ + { "isolate", 2, 2, VERB_ONLINE_ONLY, verb_start }, + { "kill", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_kill }, + { "clean", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_clean_or_freeze }, + { "freeze", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_clean_or_freeze }, + { "thaw", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_clean_or_freeze }, + { "is-active", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_is_active }, + { "check", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_is_active }, /* deprecated alias of is-active */ + { "is-failed", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_is_failed }, + { "show", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_show }, + { "cat", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_cat }, + { "status", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_show }, + { "help", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_show }, + { "daemon-reload", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_daemon_reload }, + { "daemon-reexec", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_daemon_reload }, + { "log-level", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_log_setting }, + { "log-target", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_log_setting }, + { "service-log-level", 2, 3, VERB_ONLINE_ONLY, verb_service_log_setting }, + { "service-log-target", 2, 3, VERB_ONLINE_ONLY, verb_service_log_setting }, + { "service-watchdogs", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_service_watchdogs }, + { "show-environment", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_show_environment }, + { "set-environment", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_set_environment }, + { "unset-environment", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_set_environment }, + { "import-environment", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_import_environment }, + { "halt", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, + { "poweroff", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, + { "reboot", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_start_system_special }, + { "kexec", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, + { "suspend", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, + { "hibernate", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, + { "hybrid-sleep", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, + { "suspend-then-hibernate",VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, + { "default", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_special }, + { "rescue", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, + { "emergency", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_start_system_special }, + { "exit", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_start_special }, + { "reset-failed", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_reset_failed }, + { "enable", 2, VERB_ANY, 0, verb_enable }, + { "disable", 2, VERB_ANY, 0, verb_enable }, + { "is-enabled", 2, VERB_ANY, 0, verb_is_enabled }, + { "reenable", 2, VERB_ANY, 0, verb_enable }, + { "preset", 2, VERB_ANY, 0, verb_enable }, + { "preset-all", VERB_ANY, 1, 0, verb_preset_all }, + { "mask", 2, VERB_ANY, 0, verb_enable }, + { "unmask", 2, VERB_ANY, 0, verb_enable }, + { "link", 2, VERB_ANY, 0, verb_enable }, + { "revert", 2, VERB_ANY, 0, verb_enable }, + { "switch-root", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_switch_root }, + { "list-dependencies", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_list_dependencies }, + { "set-default", 2, 2, 0, verb_set_default }, + { "get-default", VERB_ANY, 1, 0, verb_get_default }, + { "set-property", 3, VERB_ANY, VERB_ONLINE_ONLY, verb_set_property }, + { "is-system-running", VERB_ANY, 1, 0, verb_is_system_running }, + { "add-wants", 3, VERB_ANY, 0, verb_add_dependency }, + { "add-requires", 3, VERB_ANY, 0, verb_add_dependency }, + { "edit", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_edit }, + { "bind", 3, 4, VERB_ONLINE_ONLY, verb_bind }, + { "mount-image", 4, 5, VERB_ONLINE_ONLY, verb_mount_image }, {} }; From 623461c13074542b9a4dd2e7f605b6b7f8be5286 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 21 Feb 2022 17:11:52 +0100 Subject: [PATCH 2/2] systemctl: rework daemon_reload() functions Let's split out the inner parts of verb_daemon_reload() as a function daemon_reload() and then stop using the former outside of the verbs logic, and instead call the latter whenever we need to reload the daemon as auxiliary opeation. This should make our logic more systematic as we don't have to provide fake or misleading argc/argv to verb_daemon_reload() anymore. --- src/systemctl/systemctl-add-dependency.c | 4 +- src/systemctl/systemctl-compat-telinit.c | 11 +++--- src/systemctl/systemctl-daemon-reload.c | 47 ++++++++++++++++-------- src/systemctl/systemctl-daemon-reload.h | 4 ++ src/systemctl/systemctl-edit.c | 7 +++- src/systemctl/systemctl-enable.c | 12 ++++-- src/systemctl/systemctl-preset-all.c | 4 +- src/systemctl/systemctl-set-default.c | 8 ++-- src/systemctl/systemctl.c | 4 +- 9 files changed, 68 insertions(+), 33 deletions(-) diff --git a/src/systemctl/systemctl-add-dependency.c b/src/systemctl/systemctl-add-dependency.c index 9276ed3e2b..120798b33f 100644 --- a/src/systemctl/systemctl-add-dependency.c +++ b/src/systemctl/systemctl-add-dependency.c @@ -78,7 +78,9 @@ int verb_add_dependency(int argc, char *argv[], void *userdata) { goto finish; } - r = verb_daemon_reload(argc, argv, userdata); + r = daemon_reload(ACTION_RELOAD, /* graceful= */ false); + if (r > 0) + r = 0; } finish: diff --git a/src/systemctl/systemctl-compat-telinit.c b/src/systemctl/systemctl-compat-telinit.c index 1e771ef4a6..20325e5e1c 100644 --- a/src/systemctl/systemctl-compat-telinit.c +++ b/src/systemctl/systemctl-compat-telinit.c @@ -142,13 +142,14 @@ int start_with_fallback(void) { } int reload_with_fallback(void) { - /* First, try systemd via D-Bus. */ - if (verb_daemon_reload(0, NULL, NULL) >= 0) - return 0; - /* Nothing else worked, so let's try signals */ assert(IN_SET(arg_action, ACTION_RELOAD, ACTION_REEXEC)); + /* First, try systemd via D-Bus */ + if (daemon_reload(arg_action, /* graceful= */ true) > 0) + return 0; + + /* That didn't work, so let's try signals */ if (kill(1, arg_action == ACTION_RELOAD ? SIGHUP : SIGTERM) < 0) return log_error_errno(errno, "kill() failed: %m"); @@ -157,7 +158,7 @@ int reload_with_fallback(void) { int exec_telinit(char *argv[]) { (void) rlimit_nofile_safe(); - execv(TELINIT, argv); + (void) execv(TELINIT, argv); return log_error_errno(SYNTHETIC_ERRNO(EIO), "Couldn't find an alternative telinit implementation to spawn."); diff --git a/src/systemctl/systemctl-daemon-reload.c b/src/systemctl/systemctl-daemon-reload.c index 35a10e84cc..33de7d161e 100644 --- a/src/systemctl/systemctl-daemon-reload.c +++ b/src/systemctl/systemctl-daemon-reload.c @@ -6,7 +6,7 @@ #include "systemctl-util.h" #include "systemctl.h" -int verb_daemon_reload(int argc, char *argv[], void *userdata) { +int daemon_reload(enum action action, bool graceful) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; const char *method; @@ -19,7 +19,7 @@ int verb_daemon_reload(int argc, char *argv[], void *userdata) { polkit_agent_open_maybe(); - switch (arg_action) { + switch (action) { case ACTION_RELOAD: method = "Reload"; @@ -29,13 +29,8 @@ int verb_daemon_reload(int argc, char *argv[], void *userdata) { method = "Reexecute"; break; - case ACTION_SYSTEMCTL: - method = streq(argv[0], "daemon-reexec") ? "Reexecute" : - /* "daemon-reload" */ "Reload"; - break; - default: - assert_not_reached(); + return -EINVAL; } r = bus_message_new_method_call(bus, &m, bus_systemd_mgr, method); @@ -50,14 +45,36 @@ int verb_daemon_reload(int argc, char *argv[], void *userdata) { r = sd_bus_call(bus, m, DEFAULT_TIMEOUT_USEC * 2, &error, NULL); /* On reexecution, we expect a disconnect, not a reply */ - if (IN_SET(r, -ETIMEDOUT, -ECONNRESET) && streq(method, "Reexecute")) - r = 0; + if (IN_SET(r, -ETIMEDOUT, -ECONNRESET) && action == ACTION_REEXEC) + return 1; + if (r < 0) { + if (graceful) { /* If graceful mode is selected, debug log, but don't fail */ + log_debug_errno(r, "Failed to reload daemon via the bus, ignoring: %s", bus_error_message(&error, r)); + return 0; + } - if (r < 0 && arg_action == ACTION_SYSTEMCTL) return log_error_errno(r, "Failed to reload daemon: %s", bus_error_message(&error, r)); + } - /* Note that for the legacy commands (i.e. those with action != ACTION_SYSTEMCTL) we support - * fallbacks to the old ways of doing things, hence don't log any error in that case here. */ - - return r < 0 ? r : 0; + return 1; +} + +int verb_daemon_reload(int argc, char *argv[], void *userdata) { + enum action a; + int r; + + assert(argc >= 1); + + if (streq(argv[0], "daemon-reexec")) + a = ACTION_REEXEC; + else if (streq(argv[0], "daemon-reload")) + a = ACTION_RELOAD; + else + assert_not_reached(); + + r = daemon_reload(a, /* graceful= */ false); + if (r < 0) + return r; + + return 0; } diff --git a/src/systemctl/systemctl-daemon-reload.h b/src/systemctl/systemctl-daemon-reload.h index d4215cc37c..ced34ce44e 100644 --- a/src/systemctl/systemctl-daemon-reload.h +++ b/src/systemctl/systemctl-daemon-reload.h @@ -1,4 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "systemctl.h" + +int daemon_reload(enum action, bool graceful); + int verb_daemon_reload(int argc, char *argv[], void *userdata); diff --git a/src/systemctl/systemctl-edit.c b/src/systemctl/systemctl-edit.c index 4b19bf7015..f5123e80c1 100644 --- a/src/systemctl/systemctl-edit.c +++ b/src/systemctl/systemctl-edit.c @@ -569,8 +569,11 @@ int verb_edit(int argc, char *argv[], void *userdata) { r = 0; - if (!arg_no_reload && !install_client_side()) - r = verb_daemon_reload(argc, argv, userdata); + if (!arg_no_reload && !install_client_side()) { + r = daemon_reload(ACTION_RELOAD, /* graceful= */ false); + if (r > 0) + r = 0; + } end: STRV_FOREACH_PAIR(original, tmp, paths) { diff --git a/src/systemctl/systemctl-enable.c b/src/systemctl/systemctl-enable.c index f258d9643b..3da2cd928a 100644 --- a/src/systemctl/systemctl-enable.c +++ b/src/systemctl/systemctl-enable.c @@ -86,7 +86,9 @@ int verb_enable(int argc, char *argv[], void *userdata) { if (strv_isempty(names)) { if (arg_no_reload || install_client_side()) return 0; - return verb_daemon_reload(argc, argv, userdata); + + r = daemon_reload(ACTION_RELOAD, /* graceful= */ false); + return r > 0 ? 0 : r; } if (streq(verb, "disable")) { @@ -234,9 +236,11 @@ int verb_enable(int argc, char *argv[], void *userdata) { goto finish; /* Try to reload if enabled */ - if (!arg_no_reload) - r = verb_daemon_reload(argc, argv, userdata); - else + if (!arg_no_reload) { + r = daemon_reload(ACTION_RELOAD, /* graceful= */ false); + if (r > 0) + r = 0; + } else r = 0; } diff --git a/src/systemctl/systemctl-preset-all.c b/src/systemctl/systemctl-preset-all.c index fa98a9bf80..8e36ddc0c0 100644 --- a/src/systemctl/systemctl-preset-all.c +++ b/src/systemctl/systemctl-preset-all.c @@ -51,7 +51,9 @@ int verb_preset_all(int argc, char *argv[], void *userdata) { goto finish; } - r = verb_daemon_reload(argc, argv, userdata); + r = daemon_reload(ACTION_RELOAD, /* graceful= */ false); + if (r > 0) + r = 0; } finish: diff --git a/src/systemctl/systemctl-set-default.c b/src/systemctl/systemctl-set-default.c index db149e78cf..5f9186aa38 100644 --- a/src/systemctl/systemctl-set-default.c +++ b/src/systemctl/systemctl-set-default.c @@ -132,9 +132,11 @@ int verb_set_default(int argc, char *argv[], void *userdata) { goto finish; /* Try to reload if enabled */ - if (!arg_no_reload) - r = verb_daemon_reload(argc, argv, userdata); - else + if (!arg_no_reload) { + r = daemon_reload(ACTION_RELOAD, /* graceful= */ false); + if (r > 0) + r = 0; + } else r = 0; } diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index ec29e12e39..e81703ebe8 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -1051,8 +1051,8 @@ static int systemctl_main(int argc, char *argv[]) { { "cat", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_cat }, { "status", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_show }, { "help", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_show }, - { "daemon-reload", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_daemon_reload }, - { "daemon-reexec", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_daemon_reload }, + { "daemon-reload", 1, 1, VERB_ONLINE_ONLY, verb_daemon_reload }, + { "daemon-reexec", 1, 1, VERB_ONLINE_ONLY, verb_daemon_reload }, { "log-level", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_log_setting }, { "log-target", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_log_setting }, { "service-log-level", 2, 3, VERB_ONLINE_ONLY, verb_service_log_setting },