[lxc-devel] [lxc/master] confile: expand lxc.environment

brauner on Github lxc-bot at linuxcontainers.org
Sat Mar 31 00:46:02 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 646 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180331/0b77eb6d/attachment.bin>
-------------- next part --------------
From b98b8fa6520b953c427b935bed3ddb39a2f9e97c Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 31 Mar 2018 02:39:28 +0200
Subject: [PATCH] confile: expand lxc.environment

When a bare environment variable is specified then retrieve the value from the
current environment. For example, setting

lxc.environment = PATH

will cause LXC to inherit the value of PATH from the current environment.

Suggested-by: Jonathan Calmels <jcalmels at nvidia.com>
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index c1b4638d9..9704bbbec 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1096,7 +1096,21 @@ static int set_config_environment(const char *key, const char *value,
 	if (!list_item)
 		goto on_error;
 
-	list_item->elem = strdup(value);
+	if (!strchr(value, '=')) {
+		const char *env_val;
+		const char *env_key = value;
+		const char *env_var[3] = {0};
+
+		env_val = getenv(env_key);
+		if (!env_val)
+			goto on_error;
+
+		env_var[0] = env_key;
+		env_var[1] = env_val;
+		list_item->elem = lxc_string_join("=", env_var, false);
+	} else {
+		list_item->elem = strdup(value);
+	}
 
 	if (!list_item->elem)
 		goto on_error;


More information about the lxc-devel mailing list