]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Add the remaining bits for lxc.environment
authorStéphane Graber <stgraber@ubuntu.com>
Mon, 21 Jul 2014 16:20:58 +0000 (18:20 +0200)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 31 Jul 2014 17:54:36 +0000 (13:54 -0400)
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@ubuntu.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c

index e930b4de63e8f378032732773467687d8d4376d8..d6f3c22185fb5b4316ddd55d4abdd384a1185810 100644 (file)
@@ -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);
 }
 
index 1bc6ba310989d9ce4ff6711587080c55f76c841b..5ada506bbc545e1fe52201453cbaf7b67441985d 100644 (file)
@@ -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);
index 44e28d5a33eca64f1a7c684179edf1416001e972..1e5ffe3295d1b0b778af68f5a01f4ef0dcde2e36 100644 (file)
@@ -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);
 }