lxc/0008-isulad-modify-exit-code-and-stop-signal.patch
2019-12-25 15:57:42 +08:00

107 lines
3.5 KiB
Diff

From ca497ede318c29a609f7d4bfe0747b6253cb77fc Mon Sep 17 00:00:00 2001
From: tanyifeng <tanyifeng1@huawei.com>
Date: Fri, 11 Jan 2019 17:44:53 +0800
Subject: [PATCH 008/131] 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 <lifeng68@huawei.com>
---
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 b4cacce2..1d7f5bea 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 72e2de27..d64bdac1 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;
--
2.23.0