From 5d6aea523f0a89a1ef57c409de234c9b22b14eb4 Mon Sep 17 00:00:00 2001 From: tanyifeng Date: Fri, 11 Jan 2019 17:44:53 +0800 Subject: [PATCH 008/138] isulad: modify exit code and stop signal 1. modify default stop signal and disable reboot by signal. 2. send '128 + signal' if container is killed by signal. Signed-off-by: LiFeng --- src/lxc/lxccontainer.c | 6 ++---- src/lxc/start.c | 33 ++++++++++++++++----------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index b4cacce..1d7f5be 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -2069,7 +2069,8 @@ static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout) { int killret, ret; pid_t pid; - int haltsignal = SIGPWR, state_client_fd = -EBADF; + // isulad: keep default signal the same as docker + int haltsignal = SIGTERM, state_client_fd = -EBADF; lxc_state_t states[MAX_STATE] = {0}; if (!c) @@ -2082,11 +2083,8 @@ static bool do_lxcapi_shutdown(struct lxc_container *c, int timeout) if (pid <= 0) return true; - /* Detect whether we should send SIGRTMIN + 3 (e.g. systemd). */ if (c->lxc_conf && c->lxc_conf->haltsignal) haltsignal = c->lxc_conf->haltsignal; - else if (task_blocks_signal(pid, (SIGRTMIN + 3))) - haltsignal = (SIGRTMIN + 3); /* Add a new state client before sending the shutdown signal so that we * don't miss a state. diff --git a/src/lxc/start.c b/src/lxc/start.c index 72e2de2..d64bdac 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -1893,11 +1893,14 @@ out_abort: return -1; } +// isulad: send '128 + signal' if container is killed by signal. +#define ExitSignalOffset 128 + int __lxc_start(const char *name, struct lxc_handler *handler, struct lxc_operations* ops, void *data, const char *lxcpath, bool daemonize, int *error_num) { - int ret, status; + int ret, status, exit_code; struct lxc_conf *conf = handler->conf; ret = lxc_init(name, handler); @@ -1966,22 +1969,18 @@ int __lxc_start(const char *name, struct lxc_handler *handler, * reboot. This should mean it was an lxc-execute which simply exited. * In any case, treat it as a 'halt'. */ + // isulad: recored log for container init exit if (WIFSIGNALED(status)) { - switch(WTERMSIG(status)) { - case SIGINT: /* halt */ - DEBUG("Container \"%s\" is halting", name); - break; - case SIGHUP: /* reboot */ - DEBUG("Container \"%s\" is rebooting", name); - handler->conf->reboot = REBOOT_REQ; - break; - case SIGSYS: /* seccomp */ - DEBUG("Container \"%s\" violated its seccomp policy", name); - break; - default: - DEBUG("Unknown exit status for container \"%s\" init %d", name, WTERMSIG(status)); - break; - } + int signal = WTERMSIG(status); + signal = WTERMSIG(status); + exit_code = ExitSignalOffset + signal; + ERROR("Container \"%s\" init exited with signal %d", name, signal); + } else if (WIFEXITED(status)) { + exit_code = WEXITSTATUS(status); + ERROR("Container \"%s\" init exited with status %d", name, exit_code); + } else { + exit_code = -1; + ERROR("Container \"%s\" init exited with unknown status", name); } ret = lxc_restore_phys_nics_to_netns(handler); @@ -1994,7 +1993,7 @@ int __lxc_start(const char *name, struct lxc_handler *handler, handler->pinfd = -1; } - lxc_monitor_send_exit_code(name, status, handler->lxcpath); + lxc_monitor_send_exit_code(name, exit_code, handler->lxcpath); lxc_error_set_and_log(handler->pid, status); if (error_num) *error_num = handler->exit_status; -- 1.8.3.1