[lxc-devel] [PATCH] Clear environment for container

Stéphane Graber stgraber at ubuntu.com
Sat Dec 22 10:32:52 UTC 2012


On 12/20/2012 11:14 PM, Serge Hallyn wrote:
> Clear env before starting a container.  Do it right before setting
> the container=lxc variable.
> 
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>

Acked-by: Stéphane Graber <stgraber at ubuntu.com>

And applied to staging. Thanks

> ---
>  src/lxc/lxc_start.c    | 4 ++++
>  src/lxc/lxccontainer.c | 5 +++++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
> index cedd908..fb756dd 100644
> --- a/src/lxc/lxc_start.c
> +++ b/src/lxc/lxc_start.c
> @@ -130,6 +130,10 @@ int main(int argc, char *argv[])
>  			 my_args.progname, my_args.quiet))
>  		return err;
>  
> +	if (clearenv()) {
> +		SYSERROR("failed to clear environment");
> +		/* don't error out though */
> +	}
>  	if (putenv("container=lxc")) {
>  		SYSERROR("failed to set environment variable");
>  		return err;
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index fd77aac..5919d2c 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -364,6 +364,11 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv
>  		setsid();
>  	}
>  
> +	if (clearenv()) {
> +		SYSERROR("failed to clear environment");
> +		/* don't error out though */
> +	}
> +
>  	if (putenv("container=lxc")) {
>  		fprintf(stderr, "failed to set environment variable");
>  		if (daemonize) {
> 


-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 899 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20121222/c186bd16/attachment.pgp>


More information about the lxc-devel mailing list