From 9b9881d75b712ea813c46e01346e023523f8abe2 Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Fri, 10 Nov 2017 14:57:52 +0000 Subject: [PATCH] core: add missing error_message cases (#6911) We neglected to set error_message for errors which occur _after_ the `finish` label. These fatal errors only happen in paths where `finish` was reached successfully, i.e. error_message has not already been set (and this analysis is simple enough that this need not cause too much headaches. Also our new assignments to error_message come immediately after execve() calls, which would have lost the error_message if it had been set). Also print a status message when we fail to exec init, otherwise the only sign the user will see is `# ` :). This addresses the lack of error messages pointed out in issue #6827. --- src/core/emergency-action.c | 2 +- src/core/main.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/emergency-action.c b/src/core/emergency-action.c index 90232bc57a..f9110c55ce 100644 --- a/src/core/emergency-action.c +++ b/src/core/emergency-action.c @@ -31,7 +31,7 @@ static void log_and_status(Manager *m, const char *message, const char *reason) { log_warning("%s: %s", message, reason); manager_status_printf(m, STATUS_TYPE_EMERGENCY, - ANSI_HIGHLIGHT_RED " !! " ANSI_NORMAL, + ANSI_HIGHLIGHT_RED " !! " ANSI_NORMAL, "%s: %s", message, reason); } diff --git a/src/core/main.c b/src/core/main.c index b9bc2f6844..3e766f0645 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -2158,6 +2158,10 @@ finish: args[0] = "/sbin/init"; (void) execv(args[0], (char* const*) args); + manager_status_printf(NULL, STATUS_TYPE_EMERGENCY, + ANSI_HIGHLIGHT_RED " !! " ANSI_NORMAL, + "Failed to execute /sbin/init"); + if (errno == ENOENT) { log_warning("No /sbin/init, trying fallback"); @@ -2167,6 +2171,8 @@ finish: log_error_errno(errno, "Failed to execute /bin/sh, giving up: %m"); } else log_warning_errno(errno, "Failed to execute /sbin/init, giving up: %m"); + + error_message = "Failed to execute fallback shell"; } arg_serialization = safe_fclose(arg_serialization); @@ -2254,6 +2260,7 @@ finish: execve(SYSTEMD_SHUTDOWN_BINARY_PATH, (char **) command_line, env_block); log_error_errno(errno, "Failed to execute shutdown binary, %s: %m", getpid_cached() == 1 ? "freezing" : "quitting"); + error_message = "Failed to execute shutdown binary"; } if (getpid_cached() == 1) {