diff --git a/src/core/emergency-action.c b/src/core/emergency-action.c index 9731aef5c4..09f8d74092 100644 --- a/src/core/emergency-action.c +++ b/src/core/emergency-action.c @@ -47,7 +47,7 @@ void emergency_action( case EMERGENCY_ACTION_REBOOT: log_and_status(m, warn, "Rebooting", reason); - (void) update_reboot_parameter_and_warn(reboot_arg); + (void) update_reboot_parameter_and_warn(reboot_arg, true); (void) manager_add_job_by_name_and_warn(m, JOB_START, SPECIAL_REBOOT_TARGET, JOB_REPLACE_IRREVERSIBLY, NULL); break; @@ -55,7 +55,7 @@ void emergency_action( case EMERGENCY_ACTION_REBOOT_FORCE: log_and_status(m, warn, "Forcibly rebooting", reason); - (void) update_reboot_parameter_and_warn(reboot_arg); + (void) update_reboot_parameter_and_warn(reboot_arg, true); m->objective = MANAGER_REBOOT; break; diff --git a/src/shared/reboot-util.c b/src/shared/reboot-util.c index ca40159b96..6d5eee0317 100644 --- a/src/shared/reboot-util.c +++ b/src/shared/reboot-util.c @@ -12,10 +12,13 @@ #include "umask-util.h" #include "virt.h" -int update_reboot_parameter_and_warn(const char *parameter) { +int update_reboot_parameter_and_warn(const char *parameter, bool keep) { int r; if (isempty(parameter)) { + if (keep) + return 0; + if (unlink("/run/systemd/reboot-param") < 0) { if (errno == ENOENT) return 0; diff --git a/src/shared/reboot-util.h b/src/shared/reboot-util.h index d459333efc..ac59b7d79c 100644 --- a/src/shared/reboot-util.h +++ b/src/shared/reboot-util.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #pragma once -int update_reboot_parameter_and_warn(const char *parameter); +int update_reboot_parameter_and_warn(const char *parameter, bool keep); typedef enum RebootFlags { REBOOT_LOG = 1 << 0, /* log about what we are going to do and all errors */ diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index afe6f84f77..d49d3878a9 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3735,7 +3735,7 @@ static int start_special(int argc, char *argv[], void *userdata) { return r; if (a == ACTION_REBOOT && argc > 1) { - r = update_reboot_parameter_and_warn(argv[1]); + r = update_reboot_parameter_and_warn(argv[1], false); if (r < 0) return r; @@ -8444,7 +8444,7 @@ static int halt_parse_argv(int argc, char *argv[]) { } if (arg_action == ACTION_REBOOT && (argc == optind || argc == optind + 1)) { - r = update_reboot_parameter_and_warn(argc == optind + 1 ? argv[optind] : NULL); + r = update_reboot_parameter_and_warn(argc == optind + 1 ? argv[optind] : NULL, false); if (r < 0) return r; } else if (optind < argc)