diff options
author | David Tardon <dtardon@redhat.com> | 2023-03-30 12:49:15 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2023-04-11 15:34:13 +0200 |
commit | 48a50accfe154ebd1459179cf659103040a1e3c1 (patch) | |
tree | 6439a63686d129517babf2107aa68f53dc8abbf8 /src/machine/machinectl.c | |
parent | 8df3e0eec5d3f0e1e7d8121681472f018e273af4 (diff) | |
download | systemd-48a50accfe154ebd1459179cf659103040a1e3c1.tar.gz |
machinectl: do not repeat the same comparison
Diffstat (limited to 'src/machine/machinectl.c')
-rw-r--r-- | src/machine/machinectl.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 2631f33e87..f56ca90b0d 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -1762,12 +1762,14 @@ static int enable_machine(int argc, char *argv[], void *userdata) { const char *method; sd_bus *bus = ASSERT_PTR(userdata); int r; + bool enable; CLEANUP_ARRAY(changes, n_changes, install_changes_free); polkit_agent_open_if_enabled(arg_transport, arg_ask_password); - method = streq(argv[0], "enable") ? "EnableUnitFiles" : "DisableUnitFiles"; + enable = streq(argv[0], "enable"); + method = enable ? "EnableUnitFiles" : "DisableUnitFiles"; r = bus_message_new_method_call(bus, &m, bus_systemd_mgr, method); if (r < 0) @@ -1777,7 +1779,7 @@ static int enable_machine(int argc, char *argv[], void *userdata) { if (r < 0) return bus_log_create_error(r); - if (streq(argv[0], "enable")) { + if (enable) { r = sd_bus_message_append(m, "s", "machines.target"); if (r < 0) return bus_log_create_error(r); @@ -1807,7 +1809,7 @@ static int enable_machine(int argc, char *argv[], void *userdata) { if (r < 0) return bus_log_create_error(r); - if (streq(argv[0], "enable")) + if (enable) r = sd_bus_message_append(m, "bb", false, false); else r = sd_bus_message_append(m, "b", false); @@ -1818,7 +1820,7 @@ static int enable_machine(int argc, char *argv[], void *userdata) { if (r < 0) return log_error_errno(r, "Failed to enable or disable unit: %s", bus_error_message(&error, r)); - if (streq(argv[0], "enable")) { + if (enable) { r = sd_bus_message_read(reply, "b", NULL); if (r < 0) return bus_log_parse_error(r); @@ -1835,7 +1837,7 @@ static int enable_machine(int argc, char *argv[], void *userdata) { if (arg_now) { _cleanup_strv_free_ char **new_args = NULL; - new_args = strv_new(streq(argv[0], "enable") ? "start" : "poweroff"); + new_args = strv_new(enable ? "start" : "poweroff"); if (!new_args) return log_oom(); @@ -1843,7 +1845,7 @@ static int enable_machine(int argc, char *argv[], void *userdata) { if (r < 0) return log_oom(); - if (streq(argv[0], "enable")) + if (enable) return start_machine(strv_length(new_args), new_args, userdata); return poweroff_machine(strv_length(new_args), new_args, userdata); |