[lxc-devel] [lxc/master] utils: fix lxc_set_death_signal()

brauner on Github lxc-bot at linuxcontainers.org
Tue Oct 2 19:04:59 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181002/fc7f5f13/attachment.bin>
-------------- next part --------------
From c7f493aee01806ec154d2af5c84a41a9baeecbe2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 2 Oct 2018 20:59:34 +0200
Subject: [PATCH] utils: fix lxc_set_death_signal()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/start.c | 6 +++---
 src/lxc/utils.c | 9 +++------
 src/lxc/utils.h | 2 +-
 3 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/lxc/start.c b/src/lxc/start.c
index 4f805525b..5899ea07b 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -1068,7 +1068,7 @@ static int do_start(void *data)
 	 * exit before we set the pdeath signal leading to a unsupervized
 	 * container.
 	 */
-	ret = lxc_set_death_signal(SIGKILL);
+	ret = lxc_set_death_signal(SIGKILL, 0);
 	if (ret < 0) {
 		SYSERROR("Failed to set PR_SET_PDEATHSIG to SIGKILL");
 		goto out_warn_father;
@@ -1146,7 +1146,7 @@ static int do_start(void *data)
 			goto out_warn_father;
 
 		/* set{g,u}id() clears deathsignal */
-		ret = lxc_set_death_signal(SIGKILL);
+		ret = lxc_set_death_signal(SIGKILL, 0);
 		if (ret < 0) {
 			SYSERROR("Failed to set PR_SET_PDEATHSIG to SIGKILL");
 			goto out_warn_father;
@@ -1388,7 +1388,7 @@ static int do_start(void *data)
 	}
 
 	if (handler->conf->monitor_signal_pdeath != SIGKILL) {
-		ret = lxc_set_death_signal(handler->conf->monitor_signal_pdeath);
+		ret = lxc_set_death_signal(handler->conf->monitor_signal_pdeath, 0);
 		if (ret < 0) {
 			SYSERROR("Failed to set PR_SET_PDEATHSIG to %d",
 				 handler->conf->monitor_signal_pdeath);
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index af0190fa3..1af6f512c 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -1652,7 +1652,7 @@ uint64_t lxc_find_next_power2(uint64_t n)
 	return n;
 }
 
-int lxc_set_death_signal(int signal)
+int lxc_set_death_signal(int signal, pid_t parent)
 {
 	int ret;
 	pid_t ppid;
@@ -1662,11 +1662,8 @@ int lxc_set_death_signal(int signal)
 
 	/* Check whether we have been orphaned. */
 	ppid = (pid_t)syscall(SYS_getppid);
-	if (ppid == 1) {
-		pid_t self;
-
-		self = lxc_raw_getpid();
-		ret = kill(self, SIGKILL);
+	if (ppid != parent) {
+		ret = raise(SIGKILL);
 		if (ret < 0)
 			return -1;
 	}
diff --git a/src/lxc/utils.h b/src/lxc/utils.h
index 6e53f71a1..7bb361cfb 100644
--- a/src/lxc/utils.h
+++ b/src/lxc/utils.h
@@ -434,7 +434,7 @@ static inline pid_t lxc_raw_gettid(void)
 }
 
 /* Set a signal the child process will receive after the parent has died. */
-extern int lxc_set_death_signal(int signal);
+extern int lxc_set_death_signal(int signal, pid_t parent);
 extern int fd_cloexec(int fd, bool cloexec);
 extern int recursive_destroy(char *dirname);
 extern int lxc_setup_keyring(void);


More information about the lxc-devel mailing list