From bb25977244aedd73016778c75d4a7ad7d26c7009 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 20 Nov 2018 13:16:48 +0100 Subject: [PATCH] main: don't freeze PID 1 in containers, exit with non-zero instead After all we have a nice way to propagate total failures, hence let's use it. --- src/core/main.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 5272df3e3f..9469512d4e 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -130,7 +130,14 @@ static uint64_t arg_default_tasks_max = UINT64_MAX; static sd_id128_t arg_machine_id = {}; static EmergencyAction arg_cad_burst_action = EMERGENCY_ACTION_REBOOT_FORCE; -_noreturn_ static void freeze_or_reboot(void) { +_noreturn_ static void freeze_or_exit_or_reboot(void) { + + /* If we are running in a contianer, let's prefer exiting, after all we can propagate an exit code to the + * container manager, and thus inform it that something went wrong. */ + if (detect_container() > 0) { + log_emergency("Exiting PID 1..."); + exit(EXIT_EXCEPTION); + } if (arg_crash_reboot) { log_notice("Rebooting in 10s..."); @@ -238,7 +245,7 @@ _noreturn_ static void crash(int sig) { } } - freeze_or_reboot(); + freeze_or_exit_or_reboot(); } static void install_crash_handler(void) { @@ -2622,8 +2629,8 @@ finish: if (error_message) manager_status_printf(NULL, STATUS_TYPE_EMERGENCY, ANSI_HIGHLIGHT_RED "!!!!!!" ANSI_NORMAL, - "%s, freezing.", error_message); - freeze_or_reboot(); + "%s.", error_message); + freeze_or_exit_or_reboot(); } return retval;