[lxc-devel] [lxc/master] start: move env setup before container setup

brauner on Github lxc-bot at linuxcontainers.org
Tue Sep 12 19:28:20 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 466 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170912/98dd9ee7/attachment.bin>
-------------- next part --------------
From 0cda830d6cf6a95e19ffacdfe6dfa58484ccbd43 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 12 Sep 2017 21:23:17 +0200
Subject: [PATCH] start: move env setup before container setup

The hooks (e.g. lxc.hook.mount) should have the environment variables the user
gave us available.

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

diff --git a/src/lxc/start.c b/src/lxc/start.c
index a2fbe0d38..04d3c0f1d 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -913,6 +913,35 @@ static int do_start(void *data)
 		INFO("Unshared CLONE_NEWCGROUP.");
 	}
 
+	/* The clearenv() and putenv() calls have been moved here to allow us to
+	 * use environment variables passed to the various hooks, such as the
+	 * start hook above. Not all of the variables like CONFIG_PATH or ROOTFS
+	 * are valid in this context but others are.
+	 */
+	if (clearenv()) {
+		SYSERROR("Failed to clear environment.");
+		/* Don't error out though. */
+	}
+
+	lxc_list_for_each(iterator, &handler->conf->environment) {
+		if (putenv((char *)iterator->elem)) {
+			SYSERROR("Failed to set environment variable: %s.", (char *)iterator->elem);
+			goto out_warn_father;
+		}
+	}
+
+	if (putenv("container=lxc")) {
+		SYSERROR("Failed to set environment variable: container=lxc.");
+		goto out_warn_father;
+	}
+
+	if (handler->conf->pty_names) {
+		if (putenv(handler->conf->pty_names)) {
+			SYSERROR("Failed to set environment variable for container ptys.");
+			goto out_warn_father;
+		}
+	}
+
 	/* Setup the container, ip, names, utsname, ... */
 	ret = lxc_setup(handler);
 	close(handler->data_sock[0]);
@@ -962,35 +991,6 @@ static int do_start(void *data)
 		goto out_warn_father;
 	}
 
-	/* The clearenv() and putenv() calls have been moved here to allow us to
-	 * use environment variables passed to the various hooks, such as the
-	 * start hook above. Not all of the variables like CONFIG_PATH or ROOTFS
-	 * are valid in this context but others are.
-	 */
-	if (clearenv()) {
-		SYSERROR("Failed to clear environment.");
-		/* Don't error out though. */
-	}
-
-	lxc_list_for_each(iterator, &handler->conf->environment) {
-		if (putenv((char *)iterator->elem)) {
-			SYSERROR("Failed to set environment variable: %s.", (char *)iterator->elem);
-			goto out_warn_father;
-		}
-	}
-
-	if (putenv("container=lxc")) {
-		SYSERROR("Failed to set environment variable: container=lxc.");
-		goto out_warn_father;
-	}
-
-	if (handler->conf->pty_names) {
-		if (putenv(handler->conf->pty_names)) {
-			SYSERROR("Failed to set environment variable for container ptys.");
-			goto out_warn_father;
-		}
-	}
-
 	close(handler->sigfd);
 
 	if (devnull_fd < 0) {


More information about the lxc-devel mailing list