[lxc-devel] [PATCH 2/2] Add the remaining bits for lxc.environment

Serge Hallyn serge.hallyn at ubuntu.com
Mon Jul 21 23:47:07 UTC 2014


Quoting Stéphane Graber (stgraber at ubuntu.com):
> This adds the few missing bits so that the new lxc.environment config
> entry can be queried, cleared and saved as the others are.
> 
> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  src/lxc/conf.c    | 14 ++++++++++++++
>  src/lxc/conf.h    |  1 +
>  src/lxc/confile.c | 25 +++++++++++++++++++++++++
>  3 files changed, 40 insertions(+)
> 
> diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> index e930b4d..d6f3c22 100644
> --- a/src/lxc/conf.c
> +++ b/src/lxc/conf.c
> @@ -4376,6 +4376,19 @@ int lxc_clear_groups(struct lxc_conf *c)
>  	return 0;
>  }
>  
> +int lxc_clear_environment(struct lxc_conf *c)
> +{
> +	struct lxc_list *it,*next;
> +
> +	lxc_list_for_each_safe(it, &c->environment, next) {
> +		lxc_list_del(it);
> +		free(it->elem);
> +		free(it);
> +	}
> +	return 0;
> +}
> +
> +
>  int lxc_clear_mount_entries(struct lxc_conf *c)
>  {
>  	struct lxc_list *it,*next;
> @@ -4495,6 +4508,7 @@ void lxc_conf_free(struct lxc_conf *conf)
>  	lxc_clear_groups(conf);
>  	lxc_clear_includes(conf);
>  	lxc_clear_aliens(conf);
> +	lxc_clear_environment(conf);
>  	free(conf);
>  }
>  
> diff --git a/src/lxc/conf.h b/src/lxc/conf.h
> index 1bc6ba3..5ada506 100644
> --- a/src/lxc/conf.h
> +++ b/src/lxc/conf.h
> @@ -383,6 +383,7 @@ extern int lxc_clear_automounts(struct lxc_conf *c);
>  extern int lxc_clear_hooks(struct lxc_conf *c, const char *key);
>  extern int lxc_clear_idmaps(struct lxc_conf *c);
>  extern int lxc_clear_groups(struct lxc_conf *c);
> +extern int lxc_clear_environment(struct lxc_conf *c);
>  
>  extern int do_rootfs_setup(struct lxc_conf *conf, const char *name,
>  			   const char *lxcpath);
> diff --git a/src/lxc/confile.c b/src/lxc/confile.c
> index 2f32776..cdf8752 100644
> --- a/src/lxc/confile.c
> +++ b/src/lxc/confile.c
> @@ -1071,6 +1071,9 @@ static int config_environment(const char *key, const char *value,
>  {
>  	struct lxc_list *list_item = NULL;
>  
> +	if (!strlen(value))
> +		return lxc_clear_environment(lxc_conf);
> +
>  	list_item = malloc(sizeof(*list_item));
>  	if (!list_item)
>  		goto freak_out;
> @@ -2005,6 +2008,22 @@ static int lxc_get_item_groups(struct lxc_conf *c, char *retv, int inlen)
>  	return fulllen;
>  }
>  
> +static int lxc_get_item_environment(struct lxc_conf *c, char *retv, int inlen)
> +{
> +	int len, fulllen = 0;
> +	struct lxc_list *it;
> +
> +	if (!retv)
> +		inlen = 0;
> +	else
> +		memset(retv, 0, inlen);
> +
> +	lxc_list_for_each(it, &c->environment) {
> +		strprint(retv, inlen, "%s\n", (char *)it->elem);
> +	}
> +	return fulllen;
> +}
> +
>  static int lxc_get_item_cap_drop(struct lxc_conf *c, char *retv, int inlen)
>  {
>  	int len, fulllen = 0;
> @@ -2280,6 +2299,8 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
>  		return lxc_get_item_groups(c, retv, inlen);
>  	else if (strcmp(key, "lxc.seccomp") == 0)
>  		v = c->seccomp;
> +	else if (strcmp(key, "lxc.environment") == 0)
> +		return lxc_get_item_environment(c, retv, inlen);
>  	else return -1;
>  
>  	if (!v)
> @@ -2313,6 +2334,8 @@ int lxc_clear_config_item(struct lxc_conf *c, const char *key)
>  		lxc_seccomp_free(c);
>  		return 0;
>  	}
> +	else if (strncmp(key, "lxc.environment", 15) == 0)
> +		return lxc_clear_environment(c);
>  
>  	return -1;
>  }
> @@ -2526,4 +2549,6 @@ void write_config(FILE *fout, struct lxc_conf *c)
>  		fprintf(fout, "lxc.start.order = %d\n", c->start_order);
>  	lxc_list_for_each(it, &c->groups)
>  		fprintf(fout, "lxc.group = %s\n", (char *)it->elem);
> +	lxc_list_for_each(it, &c->environment)
> +		fprintf(fout, "lxc.environment = %s\n", (char *)it->elem);
>  }
> -- 
> 1.9.1
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list