diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/failure-action.c | 46 | ||||
-rw-r--r-- | src/core/failure-action.h | 3 | ||||
-rw-r--r-- | src/core/main.c | 2 | ||||
-rw-r--r-- | src/core/manager.c | 2 | ||||
-rw-r--r-- | src/core/shutdown.c | 3 | ||||
-rw-r--r-- | src/core/system.conf | 2 |
6 files changed, 49 insertions, 9 deletions
diff --git a/src/core/failure-action.c b/src/core/failure-action.c index ca807b68da..941747429f 100644 --- a/src/core/failure-action.c +++ b/src/core/failure-action.c @@ -40,10 +40,19 @@ int failure_action( assert(action >= 0); assert(action < _FAILURE_ACTION_MAX); - switch (action) { + if (action == FAILURE_ACTION_NONE) + return -ECANCELED; - case FAILURE_ACTION_NONE: - break; + if (m->running_as == SYSTEMD_USER) { + /* Downgrade all options to simply exiting if we run + * in user mode */ + + log_warning("Exiting as result of failure."); + m->exit_code = MANAGER_EXIT; + return -ECANCELED; + } + + switch (action) { case FAILURE_ACTION_REBOOT: { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; @@ -78,6 +87,32 @@ int failure_action( reboot(RB_AUTOBOOT); break; + case FAILURE_ACTION_POWEROFF: { + _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + + log_warning("Powering off as result of failure."); + + r = manager_add_job_by_name(m, JOB_START, SPECIAL_POWEROFF_TARGET, JOB_REPLACE, true, &error, NULL); + if (r < 0) + log_error("Failed to poweroff: %s.", bus_error_message(&error, r)); + + break; + } + + case FAILURE_ACTION_POWEROFF_FORCE: + log_warning("Forcibly powering off as result of failure."); + m->exit_code = MANAGER_POWEROFF; + break; + + case FAILURE_ACTION_POWEROFF_IMMEDIATE: + log_warning("Powering off immediately as result of failure."); + + sync(); + + log_info("Powering off."); + reboot(RB_POWER_OFF); + break; + default: assert_not_reached("Unknown failure action"); } @@ -89,6 +124,9 @@ static const char* const failure_action_table[_FAILURE_ACTION_MAX] = { [FAILURE_ACTION_NONE] = "none", [FAILURE_ACTION_REBOOT] = "reboot", [FAILURE_ACTION_REBOOT_FORCE] = "reboot-force", - [FAILURE_ACTION_REBOOT_IMMEDIATE] = "reboot-immediate" + [FAILURE_ACTION_REBOOT_IMMEDIATE] = "reboot-immediate", + [FAILURE_ACTION_POWEROFF] = "poweroff", + [FAILURE_ACTION_POWEROFF_FORCE] = "poweroff-force", + [FAILURE_ACTION_POWEROFF_IMMEDIATE] = "poweroff-immediate" }; DEFINE_STRING_TABLE_LOOKUP(failure_action, FailureAction); diff --git a/src/core/failure-action.h b/src/core/failure-action.h index 5353192f31..1af4dd987b 100644 --- a/src/core/failure-action.h +++ b/src/core/failure-action.h @@ -27,6 +27,9 @@ typedef enum FailureAction { FAILURE_ACTION_REBOOT, FAILURE_ACTION_REBOOT_FORCE, FAILURE_ACTION_REBOOT_IMMEDIATE, + FAILURE_ACTION_POWEROFF, + FAILURE_ACTION_POWEROFF_FORCE, + FAILURE_ACTION_POWEROFF_IMMEDIATE, _FAILURE_ACTION_MAX, _FAILURE_ACTION_INVALID = -1 } FailureAction; diff --git a/src/core/main.c b/src/core/main.c index ed690162bf..bd148b1b33 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -117,7 +117,7 @@ static bool arg_default_cpu_accounting = false; static bool arg_default_blockio_accounting = false; static bool arg_default_memory_accounting = false; static usec_t arg_start_timeout_usec = DEFAULT_MANAGER_START_TIMEOUT_USEC; -static FailureAction arg_start_timeout_action = FAILURE_ACTION_REBOOT_FORCE; +static FailureAction arg_start_timeout_action = FAILURE_ACTION_POWEROFF_FORCE; static char *arg_start_timeout_reboot_arg = NULL; static void nop_handler(int sig) {} diff --git a/src/core/manager.c b/src/core/manager.c index 7508fefaef..7639aeef19 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -436,7 +436,7 @@ int manager_new(SystemdRunningAs running_as, bool test_run, Manager **_m) { m->exit_code = _MANAGER_EXIT_CODE_INVALID; m->default_timer_accuracy_usec = USEC_PER_MINUTE; m->start_timeout_usec = DEFAULT_MANAGER_START_TIMEOUT_USEC; - m->start_timeout_action = FAILURE_ACTION_REBOOT_FORCE; + m->start_timeout_action = FAILURE_ACTION_POWEROFF_FORCE; m->idle_pipe[0] = m->idle_pipe[1] = m->idle_pipe[2] = m->idle_pipe[3] = -1; diff --git a/src/core/shutdown.c b/src/core/shutdown.c index 1abc140e7d..0e2ea5754f 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -435,8 +435,7 @@ int main(int argc, char *argv[]) { if (read_one_line_file(REBOOT_PARAM_FILE, ¶m) >= 0) { log_info("Rebooting with argument '%s'.", param); - syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, - LINUX_REBOOT_CMD_RESTART2, param); + syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, param); } } diff --git a/src/core/system.conf b/src/core/system.conf index 45448de328..5a723bb20e 100644 --- a/src/core/system.conf +++ b/src/core/system.conf @@ -24,7 +24,7 @@ #SystemCallArchitectures= #TimerSlackNSec= #StartTimeoutSec=15min -#StartTimeoutAction=reboot-force +#StartTimeoutAction=poweroff-force #StartTimeoutRebootArgument= #DefaultTimerAccuracySec=1min #DefaultStandardOutput=journal |