[lxc-devel] [lxc/master] start: simplify

brauner on Github lxc-bot at linuxcontainers.org
Fri Oct 19 22:07:31 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/20181019/fd099b86/attachment.bin>
-------------- next part --------------
From 9b10bef54ce7dfde831b2ff6b3182013e08388b7 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 20 Oct 2018 00:06:32 +0200
Subject: [PATCH] start: simplify

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/start.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/lxc/start.c b/src/lxc/start.c
index f0401f5fb..ab035507e 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -180,8 +180,6 @@ static bool lxc_try_preserve_namespaces(struct lxc_handler *handler,
 
 		fd = lxc_try_preserve_ns(pid, ns_info[i].proc_name);
 		if (fd < 0) {
-			handler->nsfd[i] = -EBADF;
-
 			/* Do not fail to start container on kernels that do
 			 * not support interacting with namespaces through
 			 * /proc.
@@ -295,7 +293,6 @@ int lxc_check_inherited(struct lxc_conf *conf, bool closeall,
 static int setup_signal_fd(sigset_t *oldmask)
 {
 	int ret;
-	int sig;
 	sigset_t mask;
 	const int signals[] = {SIGBUS, SIGILL, SIGSEGV, SIGWINCH};
 
@@ -304,7 +301,7 @@ static int setup_signal_fd(sigset_t *oldmask)
 	if (ret < 0)
 		return -EBADF;
 
-	for (sig = 0; sig < (sizeof(signals) / sizeof(signals[0])); sig++) {
+	for (int sig = 0; sig < (sizeof(signals) / sizeof(signals[0])); sig++) {
 		ret = sigdelset(&mask, signals[sig]);
 		if (ret < 0)
 			return -EBADF;
@@ -377,13 +374,15 @@ static int signal_handler(int fd, uint32_t events, void *data,
 	if (siginfo.ssi_signo == SIGHUP) {
 		kill(hdlr->pid, SIGTERM);
 		INFO("Killing %d since terminal hung up", hdlr->pid);
-		return hdlr->init_died ? LXC_MAINLOOP_CLOSE : LXC_MAINLOOP_CONTINUE;
+		return hdlr->init_died ? LXC_MAINLOOP_CLOSE
+				       : LXC_MAINLOOP_CONTINUE;
 	}
 
 	if (siginfo.ssi_signo != SIGCHLD) {
 		kill(hdlr->pid, siginfo.ssi_signo);
 		INFO("Forwarded signal %d to pid %d", siginfo.ssi_signo, hdlr->pid);
-		return hdlr->init_died ? LXC_MAINLOOP_CLOSE : LXC_MAINLOOP_CONTINUE;
+		return hdlr->init_died ? LXC_MAINLOOP_CLOSE
+				       : LXC_MAINLOOP_CONTINUE;
 	}
 
 	/* More robustness, protect ourself from a SIGCHLD sent
@@ -392,18 +391,24 @@ static int signal_handler(int fd, uint32_t events, void *data,
 	if (siginfo.ssi_pid != hdlr->pid) {
 		NOTICE("Received %d from pid %d instead of container init %d",
 		       siginfo.ssi_signo, siginfo.ssi_pid, hdlr->pid);
-		return hdlr->init_died ? LXC_MAINLOOP_CLOSE : LXC_MAINLOOP_CONTINUE;
+		return hdlr->init_died ? LXC_MAINLOOP_CLOSE
+				       : LXC_MAINLOOP_CONTINUE;
 	}
 
 	if (siginfo.ssi_code == CLD_STOPPED) {
 		INFO("Container init process was stopped");
-		return hdlr->init_died ? LXC_MAINLOOP_CLOSE : LXC_MAINLOOP_CONTINUE;
-	} else if (siginfo.ssi_code == CLD_CONTINUED) {
+		return hdlr->init_died ? LXC_MAINLOOP_CLOSE
+				       : LXC_MAINLOOP_CONTINUE;
+	}
+
+	if (siginfo.ssi_code == CLD_CONTINUED) {
 		INFO("Container init process was continued");
-		return hdlr->init_died ? LXC_MAINLOOP_CLOSE : LXC_MAINLOOP_CONTINUE;
+		return hdlr->init_died ? LXC_MAINLOOP_CLOSE
+				       : LXC_MAINLOOP_CONTINUE;
 	}
 
 	DEBUG("Container init process %d exited", hdlr->pid);
+
 	return LXC_MAINLOOP_CLOSE;
 }
 
@@ -649,6 +654,9 @@ void lxc_free_handler(struct lxc_handler *handler)
 	if (handler->state_socket_pair[1] >= 0)
 		close(handler->state_socket_pair[1]);
 
+	if (handler->cgroup_ops)
+		cgroup_exit(handler->cgroup_ops);
+
 	handler->conf = NULL;
 	free(handler);
 	handler = NULL;
@@ -959,7 +967,6 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
 
 	cgroup_ops->payload_destroy(cgroup_ops, handler);
 	cgroup_ops->monitor_destroy(cgroup_ops, handler);
-	cgroup_exit(cgroup_ops);
 
 	if (handler->conf->reboot == REBOOT_NONE) {
 		/* For all new state clients simply close the command socket.


More information about the lxc-devel mailing list