diff options
author | Mike Yuan <me@yhndnzj.com> | 2023-10-17 14:35:31 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2023-10-18 18:12:27 +0200 |
commit | def1e20a182fba020b72f34e281110389f706030 (patch) | |
tree | e301dfa387d825e355cf16bf4976b636dcdf81c1 | |
parent | Merge pull request #29594 from poettering/cgroup-rename-ret-params (diff) | |
download | systemd-def1e20a182fba020b72f34e281110389f706030.tar.xz systemd-def1e20a182fba020b72f34e281110389f706030.zip |
systemctl: minor modernization
-rw-r--r-- | src/systemctl/systemctl-cancel-job.c | 8 | ||||
-rw-r--r-- | src/systemctl/systemctl-is-active.c | 11 | ||||
-rw-r--r-- | src/systemctl/systemctl-is-enabled.c | 6 |
3 files changed, 14 insertions, 11 deletions
diff --git a/src/systemctl/systemctl-cancel-job.c b/src/systemctl/systemctl-cancel-job.c index 3cf1369463..e9f34c151c 100644 --- a/src/systemctl/systemctl-cancel-job.c +++ b/src/systemctl/systemctl-cancel-job.c @@ -21,6 +21,8 @@ int verb_cancel(int argc, char *argv[], void *userdata) { polkit_agent_open_maybe(); + r = 0; + STRV_FOREACH(name, strv_skip(argv, 1)) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; uint32_t id; @@ -32,9 +34,9 @@ int verb_cancel(int argc, char *argv[], void *userdata) { q = bus_call_method(bus, bus_systemd_mgr, "CancelJob", &error, NULL, "u", id); if (q < 0) { - log_error_errno(q, "Failed to cancel job %"PRIu32": %s", id, bus_error_message(&error, q)); - if (r == 0) - r = q; + log_warning_errno(q, "Failed to cancel job %"PRIu32", ignoring: %s", + id, bus_error_message(&error, q)); + RET_GATHER(r, q); } } diff --git a/src/systemctl/systemctl-is-active.c b/src/systemctl/systemctl-is-active.c index 15e366ccae..023869c9ac 100644 --- a/src/systemctl/systemctl-is-active.c +++ b/src/systemctl/systemctl-is-active.c @@ -9,7 +9,7 @@ #include "systemctl-util.h" #include "systemctl.h" -static int check_unit_generic(int code, const UnitActiveState good_states[], int nb_states, char **args) { +static int check_unit_generic(int code, const UnitActiveState good_states[], size_t nb_states, char **args) { _cleanup_strv_free_ char **names = NULL; UnitActiveState active_state; sd_bus *bus; @@ -38,8 +38,8 @@ static int check_unit_generic(int code, const UnitActiveState good_states[], int if (!arg_quiet) puts(unit_active_state_to_string(active_state)); - for (int i = 0; i < nb_states; ++i) - if (good_states[i] == active_state) { + FOREACH_ARRAY(good_state, good_states, nb_states) + if (active_state == *good_state) { ok = true; break; } @@ -48,12 +48,12 @@ static int check_unit_generic(int code, const UnitActiveState good_states[], int not_found = false; } - /* We use LSB code 4 ("program or service status is unknown") - * when the corresponding unit file doesn't exist. */ + /* We use LSB code 4 ("program or service status is unknown") when the corresponding unit file doesn't exist. */ return ok ? EXIT_SUCCESS : not_found ? EXIT_PROGRAM_OR_SERVICES_STATUS_UNKNOWN : code; } int verb_is_active(int argc, char *argv[], void *userdata) { + static const UnitActiveState states[] = { UNIT_ACTIVE, UNIT_RELOADING, @@ -64,6 +64,7 @@ int verb_is_active(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-enabled.c b/src/systemctl/systemctl-is-enabled.c index 8d791deaf1..01d924f8db 100644 --- a/src/systemctl/systemctl-is-enabled.c +++ b/src/systemctl/systemctl-is-enabled.c @@ -24,9 +24,9 @@ static int show_installation_targets_client_side(const char *name) { if (r < 0) return log_error_errno(r, "Failed to get file links for %s: %m", name); - for (size_t i = 0; i < n_changes; i++) - if (changes[i].type == INSTALL_CHANGE_UNLINK) - printf(" %s\n", changes[i].path); + FOREACH_ARRAY(c, changes, n_changes) + if (c->type == INSTALL_CHANGE_UNLINK) + printf(" %s\n", c->path); return 0; } |