From 57ab90065d550b5f86e67f5d9ebc40f8a4c1297d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 29 Sep 2015 14:00:12 +0200 Subject: systemctl: split out code invoking SetExitCode() into function of its own --- src/systemctl/systemctl.c | 56 ++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 5bcea28411..56852fdb92 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3054,6 +3054,30 @@ static int prepare_firmware_setup(void) { return logind_prepare_firmware_setup(); } +static int set_exit_code(uint8_t code) { + _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + sd_bus *bus; + int r; + + r = acquire_bus(BUS_MANAGER, &bus); + if (r < 0) + return r; + + r = sd_bus_call_method( + bus, + "org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "SetExitCode", + &error, + NULL, + "y", code); + if (r < 0) + return log_error_errno(r, "Failed to execute operation: %s", bus_error_message(&error, r)); + + return 0; +} + static int start_special(char **args) { enum action a; int r; @@ -3075,39 +3099,25 @@ static int start_special(char **args) { if (r < 0) return r; - if (a == ACTION_REBOOT && args[1]) { + if (a == ACTION_REBOOT && strv_length(args) > 1) { r = update_reboot_param_file(args[1]); if (r < 0) return r; + } else if (a == ACTION_EXIT && strv_length(args) > 1) { - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - /* If the exit code is not given on the command line, don't - * reset it to zero: just keep it as it might have been set - * previously. */ uint8_t code = 0; - sd_bus *bus; - r = safe_atou8(args[1], &code); - if (r < 0) { - log_error("Invalid exit code."); - return -EINVAL; - } + /* If the exit code is not given on the command line, + * don't reset it to zero: just keep it as it might + * have been set previously. */ - r = acquire_bus(BUS_MANAGER, &bus); + r = safe_atou8(args[1], &code); if (r < 0) - return r; + return log_error_errno(r, "Invalid exit code."); - r = sd_bus_call_method( - bus, - "org.freedesktop.systemd1", - "/org/freedesktop/systemd1", - "org.freedesktop.systemd1.Manager", - "SetExitCode", - &error, - NULL, - "y", code); + r = set_exit_code(code); if (r < 0) - return log_error_errno(r, "Failed to execute operation: %s", bus_error_message(&error, r)); + return r; } if (arg_force >= 2 && -- cgit v1.2.3-54-g00ecf