From 6a6ad7af58ba541ea27300fdd05715ef9454ce8e Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Wed, 7 Oct 2009 16:06:09 +0200 Subject: [PATCH] make container to die when parent dies When the parent of the first process dies, the container stays there making very difficuly to track it and to kill. We have to use the lxc-ps --lxc and kill the processes, hoping we kill the init process of the container. That's not a big deal until we have thousand of processes in the container :) We want to keep the parent of the container init always there, this process is responsible to manage the container, provide tty, notify the container changing states and ensure self exclusion (eg. avoid to launch several containers with the same name). If this process dies, we consider that as a fatal error and we make the child process to die too. This patch will just add the prctl to to send a SIGKILL to the container init process when its parent exits For the point of view of the pid namespace, when the init process dies all the processes of the namespace are killed too. Signed-off-by: Daniel Lezcano --- src/lxc/start.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lxc/start.c b/src/lxc/start.c index 8826b8194..2e648b730 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -368,6 +368,11 @@ static int do_start(void *arg) goto out_child; } + if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0)) { + SYSERROR("failed to set pdeath signal"); + goto out_child; + } + NOTICE("exec'ing '%s'", argv[0]); execvp(argv[0], argv); -- 2.47.2