From: Stéphane Graber Date: Mon, 21 Jul 2014 16:20:58 +0000 (+0200) Subject: Add the remaining bits for lxc.environment X-Git-Tag: lxc-1.1.0.alpha2~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab799c0ba931bde0f4586fb2a61854610a0daf0d;p=thirdparty%2Flxc.git Add the remaining bits for lxc.environment 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 --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index e930b4de6..d6f3c2218 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 1bc6ba310..5ada506bb 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 44e28d5a3..1e5ffe329 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; @@ -2008,6 +2011,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; @@ -2283,6 +2302,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) @@ -2316,6 +2337,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; } @@ -2529,4 +2552,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); }