From: Christian Brauner Date: Wed, 13 Sep 2017 02:01:41 +0000 (+0200) Subject: start: set environment variables correctly X-Git-Tag: lxc-2.0.9~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=593c29a97c52be6d61e0857857e19f6d4c1442d2;p=thirdparty%2Flxc.git start: set environment variables correctly Signed-off-by: Christian Brauner --- diff --git a/src/lxc/start.c b/src/lxc/start.c index 50b348f25..fd7ba46d1 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -989,16 +989,10 @@ 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. + /* Add the requested environment variables to the current environment to + * allow them to be used by the various hooks, such as the start hook + * above. */ - 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); @@ -1070,6 +1064,21 @@ static int do_start(void *data) if (lxc_sync_barrier_parent(handler, LXC_SYNC_CGROUP_LIMITS)) goto out_warn_father; + /* Reset the environment variables the user requested in a clear + * environment. + */ + 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;