core: add missing error_message cases (#6911)
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>
Fri, 10 Nov 2017 14:57:52 +0000 (14:57 +0000)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 10 Nov 2017 14:57:52 +0000 (15:57 +0100)
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
src/core/main.c

index 90232bc..f9110c5 100644 (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);
 }
 
index b9bc2f6..3e766f0 100644 (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) {