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.
This commit is contained in:
Alan Jenkins 2017-11-10 14:57:52 +00:00 committed by Zbigniew Jędrzejewski-Szmek
parent 67595fce2d
commit 9b9881d75b
2 changed files with 8 additions and 1 deletions

View File

@ -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);
}

View File

@ -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) {