1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-06 16:59:03 +03:00

Merge pull request #10853 from poettering/thaw-containers

main: don't freeze PID 1 in containers, exit with non-zero instead
This commit is contained in:
Lennart Poettering 2018-11-20 19:35:30 +01:00 committed by GitHub
commit f81f8bac2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 11 deletions

View File

@ -130,7 +130,14 @@ static uint64_t arg_default_tasks_max = UINT64_MAX;
static sd_id128_t arg_machine_id = {}; static sd_id128_t arg_machine_id = {};
static EmergencyAction arg_cad_burst_action = EMERGENCY_ACTION_REBOOT_FORCE; 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) { if (arg_crash_reboot) {
log_notice("Rebooting in 10s..."); log_notice("Rebooting in 10s...");
@ -185,7 +192,7 @@ _noreturn_ static void crash(int sig) {
(void) kill(pid, sig); /* raise() would kill the parent */ (void) kill(pid, sig); /* raise() would kill the parent */
assert_not_reached("We shouldn't be here..."); assert_not_reached("We shouldn't be here...");
_exit(EXIT_FAILURE); _exit(EXIT_EXCEPTION);
} else { } else {
siginfo_t status; siginfo_t status;
int r; int r;
@ -231,14 +238,14 @@ _noreturn_ static void crash(int sig) {
(void) execle("/bin/sh", "/bin/sh", NULL, environ); (void) execle("/bin/sh", "/bin/sh", NULL, environ);
log_emergency_errno(errno, "execle() failed: %m"); log_emergency_errno(errno, "execle() failed: %m");
_exit(EXIT_FAILURE); _exit(EXIT_EXCEPTION);
} else { } else {
log_info("Spawned crash shell as PID "PID_FMT".", pid); log_info("Spawned crash shell as PID "PID_FMT".", pid);
(void) wait_for_terminate(pid, NULL); (void) wait_for_terminate(pid, NULL);
} }
} }
freeze_or_reboot(); freeze_or_exit_or_reboot();
} }
static void install_crash_handler(void) { static void install_crash_handler(void) {
@ -2622,8 +2629,8 @@ finish:
if (error_message) if (error_message)
manager_status_printf(NULL, STATUS_TYPE_EMERGENCY, manager_status_printf(NULL, STATUS_TYPE_EMERGENCY,
ANSI_HIGHLIGHT_RED "!!!!!!" ANSI_NORMAL, ANSI_HIGHLIGHT_RED "!!!!!!" ANSI_NORMAL,
"%s, freezing.", error_message); "%s.", error_message);
freeze_or_reboot(); freeze_or_exit_or_reboot();
} }
return retval; return retval;

View File

@ -5,6 +5,8 @@
#include <sys/prctl.h> #include <sys/prctl.h>
#include <unistd.h> #include <unistd.h>
#include "def.h"
#include "exit-status.h"
#include "fd-util.h" #include "fd-util.h"
#include "log.h" #include "log.h"
#include "missing.h" #include "missing.h"
@ -12,7 +14,6 @@
#include "process-util.h" #include "process-util.h"
#include "signal-util.h" #include "signal-util.h"
#include "time-util.h" #include "time-util.h"
#include "def.h"
static int reset_environ(const char *new_environment, size_t length) { static int reset_environ(const char *new_environment, size_t length) {
unsigned long start, end; unsigned long start, end;
@ -122,7 +123,7 @@ int stub_pid1(sd_id128_t uuid) {
if (si.si_pid == pid && si.si_code == CLD_EXITED) if (si.si_pid == pid && si.si_code == CLD_EXITED)
r = si.si_status; /* pass on exit code */ r = si.si_status; /* pass on exit code */
else else
r = 255; /* signal, coredump, timeout, … */ r = EXIT_EXCEPTION; /* signal, coredump, timeout, … */
goto finish; goto finish;
} }

View File

@ -19,9 +19,10 @@ const char* exit_status_to_string(int status, ExitStatusLevel level) {
* 79199 (Currently unmapped) * 79199 (Currently unmapped)
* 200241 systemd's private error codes (might be extended to 254 in future development) * 200241 systemd's private error codes (might be extended to 254 in future development)
* 242254 (Currently unmapped, but see above) * 242254 (Currently unmapped, but see above)
* 255 (We should probably stay away from that one, it's frequently used by applications to indicate an *
* exit reason that cannot really be expressed in a single exit status value such as a propagated * 255 EXIT_EXCEPTION (We use this to propagate exit-by-signal events. It's frequently used by others apps (like bash)
* signal or such) * to indicate exit reason that cannot really be expressed in a single exit status value such as a propagated
* signal or such, and we follow that logic here.)
*/ */
switch (status) { /* We always cover the ISO C ones */ switch (status) { /* We always cover the ISO C ones */
@ -155,6 +156,9 @@ const char* exit_status_to_string(int status, ExitStatusLevel level) {
case EXIT_CONFIGURATION_DIRECTORY: case EXIT_CONFIGURATION_DIRECTORY:
return "CONFIGURATION_DIRECTORY"; return "CONFIGURATION_DIRECTORY";
case EXIT_EXCEPTION:
return "EXCEPTION";
} }
} }

View File

@ -69,6 +69,8 @@ enum {
EXIT_CACHE_DIRECTORY, EXIT_CACHE_DIRECTORY,
EXIT_LOGS_DIRECTORY, /* 240 */ EXIT_LOGS_DIRECTORY, /* 240 */
EXIT_CONFIGURATION_DIRECTORY, EXIT_CONFIGURATION_DIRECTORY,
EXIT_EXCEPTION = 255, /* Whenever we want to propagate an abnormal/signal exit, in line with bash */
}; };
typedef enum ExitStatusLevel { typedef enum ExitStatusLevel {