[lxc-devel] [patch -lxc 3/4] lxc-init kills all processes with SIGTERM

Daniel Lezcano dlezcano at fr.ibm.com
Thu Jul 15 21:08:17 UTC 2010


When lxc-init receives a SIGTERM, let's kill all the processes of
the pid namespace with kill -1. So the exit of the container will
happen gracefully with processes death cascade.

Signed-off-by: Daniel Lezcano <dlezcano at fr.ibm.com>
---
 src/lxc/lxc_init.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c
index 5e0da5e..d91a3a1 100644
--- a/src/lxc/lxc_init.c
+++ b/src/lxc/lxc_init.c
@@ -154,11 +154,21 @@ int main(int argc, char *argv[])
 		int orphan = 0;
 		pid_t waited_pid;
 
-		if (was_interrupted) {
+		switch (was_interrupted) {
+
+		case 0:
+			break;
+
+		case SIGTERM:
+			kill(-1, SIGTERM);
+			break;
+
+		default:
 			kill(pid, was_interrupted);
-			was_interrupted = 0;
+			break;
 		}
 
+		was_interrupted = 0;
 		waited_pid = wait(&status);
 		if (waited_pid < 0) {
 			if (errno == ECHILD)
-- 
1.7.0.4





More information about the lxc-devel mailing list