Commit ab799c0b by Stéphane Graber

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: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 7c661726
...@@ -4376,6 +4376,19 @@ int lxc_clear_groups(struct lxc_conf *c) ...@@ -4376,6 +4376,19 @@ int lxc_clear_groups(struct lxc_conf *c)
return 0; 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) int lxc_clear_mount_entries(struct lxc_conf *c)
{ {
struct lxc_list *it,*next; struct lxc_list *it,*next;
...@@ -4495,6 +4508,7 @@ void lxc_conf_free(struct lxc_conf *conf) ...@@ -4495,6 +4508,7 @@ void lxc_conf_free(struct lxc_conf *conf)
lxc_clear_groups(conf); lxc_clear_groups(conf);
lxc_clear_includes(conf); lxc_clear_includes(conf);
lxc_clear_aliens(conf); lxc_clear_aliens(conf);
lxc_clear_environment(conf);
free(conf); free(conf);
} }
......
...@@ -383,6 +383,7 @@ extern int lxc_clear_automounts(struct lxc_conf *c); ...@@ -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_hooks(struct lxc_conf *c, const char *key);
extern int lxc_clear_idmaps(struct lxc_conf *c); extern int lxc_clear_idmaps(struct lxc_conf *c);
extern int lxc_clear_groups(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, extern int do_rootfs_setup(struct lxc_conf *conf, const char *name,
const char *lxcpath); const char *lxcpath);
......
...@@ -1071,6 +1071,9 @@ static int config_environment(const char *key, const char *value, ...@@ -1071,6 +1071,9 @@ static int config_environment(const char *key, const char *value,
{ {
struct lxc_list *list_item = NULL; struct lxc_list *list_item = NULL;
if (!strlen(value))
return lxc_clear_environment(lxc_conf);
list_item = malloc(sizeof(*list_item)); list_item = malloc(sizeof(*list_item));
if (!list_item) if (!list_item)
goto freak_out; goto freak_out;
...@@ -2008,6 +2011,22 @@ static int lxc_get_item_groups(struct lxc_conf *c, char *retv, int inlen) ...@@ -2008,6 +2011,22 @@ static int lxc_get_item_groups(struct lxc_conf *c, char *retv, int inlen)
return fulllen; 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) static int lxc_get_item_cap_drop(struct lxc_conf *c, char *retv, int inlen)
{ {
int len, fulllen = 0; int len, fulllen = 0;
...@@ -2283,6 +2302,8 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv, ...@@ -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); return lxc_get_item_groups(c, retv, inlen);
else if (strcmp(key, "lxc.seccomp") == 0) else if (strcmp(key, "lxc.seccomp") == 0)
v = c->seccomp; v = c->seccomp;
else if (strcmp(key, "lxc.environment") == 0)
return lxc_get_item_environment(c, retv, inlen);
else return -1; else return -1;
if (!v) if (!v)
...@@ -2316,6 +2337,8 @@ int lxc_clear_config_item(struct lxc_conf *c, const char *key) ...@@ -2316,6 +2337,8 @@ int lxc_clear_config_item(struct lxc_conf *c, const char *key)
lxc_seccomp_free(c); lxc_seccomp_free(c);
return 0; return 0;
} }
else if (strncmp(key, "lxc.environment", 15) == 0)
return lxc_clear_environment(c);
return -1; return -1;
} }
...@@ -2529,4 +2552,6 @@ void write_config(FILE *fout, struct lxc_conf *c) ...@@ -2529,4 +2552,6 @@ void write_config(FILE *fout, struct lxc_conf *c)
fprintf(fout, "lxc.start.order = %d\n", c->start_order); fprintf(fout, "lxc.start.order = %d\n", c->start_order);
lxc_list_for_each(it, &c->groups) lxc_list_for_each(it, &c->groups)
fprintf(fout, "lxc.group = %s\n", (char *)it->elem); 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);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment