From c5220a940d00fc2520c702104939d0a4cf637254 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Tue, 25 Mar 2014 14:15:44 +0100 Subject: [PATCH] systemctl: delete REBOOT_PARAM_FILE if no parameter is specified And move it to sperate function. --- src/shared/util.c | 16 ++++++++++++++++ src/shared/util.h | 6 ++++-- src/systemctl/systemctl.c | 9 +++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/shared/util.c b/src/shared/util.c index c20dff2f7..b6285abb2 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -6397,3 +6397,19 @@ void hexdump(FILE *f, const void *p, size_t s) { s -= 16; } } + +int update_reboot_param_file(const char *param) +{ + int r = 0; + + if (param) { + + r = write_string_file(REBOOT_PARAM_FILE, param); + if (r < 0) + log_error("Failed to write reboot param to " + REBOOT_PARAM_FILE": %s", strerror(-r)); + } else + unlink(REBOOT_PARAM_FILE); + + return r; +} diff --git a/src/shared/util.h b/src/shared/util.h index 891848a1d..5b060ef74 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -917,6 +917,8 @@ char* mount_test_option(const char *haystack, const char *needle); void hexdump(FILE *f, const void *p, size_t s); union file_handle_union { - struct file_handle handle; - char padding[sizeof(struct file_handle) + MAX_HANDLE_SZ]; + struct file_handle handle; + char padding[sizeof(struct file_handle) + MAX_HANDLE_SZ]; }; + +int update_reboot_param_file(const char *param); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 1b381f7a9..1717c1929 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -6018,13 +6018,10 @@ static int halt_parse_argv(int argc, char *argv[]) { } } - if (arg_action == ACTION_REBOOT && argc == optind + 1) { - r = write_string_file(REBOOT_PARAM_FILE, argv[optind]); - if (r < 0) { - log_error("Failed to write reboot param to " - REBOOT_PARAM_FILE": %s", strerror(-r)); + if (arg_action == ACTION_REBOOT && (argc == optind || argc == optind + 1)) { + r = update_reboot_param_file(argc == optind + 1 ? argv[optind] : NULL); + if (r < 0) return r; - } } else if (optind < argc) { log_error("Too many arguments."); return -EINVAL; -- 2.30.2