]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Store alien config lines
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 12 Jun 2014 13:46:37 +0000 (13:46 +0000)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 18 Jun 2014 20:56:17 +0000 (16:56 -0400)
Any config lines not starting with 'lxc.*' are ignored by lxc.  That
can be useful for third party tools, however lxc-clone does not copy such
lines.

Fix that by tracking such lines in our unexpanded config file and
printing them out at write_config().  Note two possible shortcomings here:

1. we always print out all includes followed by all aliens.  They are
not kept in order, nor ordered with respect to lxc.* lines.

2. we're still not storing comments. these could easily be added to
the alien lines, but i chose not to in particular since comments are
usually associated with other lines, so destroying the order would
destroy their value.  I could be wrong about that, and if I am it's
a trivial fix.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c

index 521a48d8cf652c7041caf46b48d5c12cf9c30a46..23ed7f35131c36dcc84d520ac20ccf68f73424cf 100644 (file)
@@ -2690,6 +2690,7 @@ struct lxc_conf *lxc_conf_init(void)
        lxc_list_init(&new->keepcaps);
        lxc_list_init(&new->id_map);
        lxc_list_init(&new->includes);
+       lxc_list_init(&new->aliens);
        for (i=0; i<NUM_LXC_HOOKS; i++)
                lxc_list_init(&new->hooks[i]);
        lxc_list_init(&new->groups);
@@ -4365,6 +4366,17 @@ static void lxc_clear_saved_nics(struct lxc_conf *conf)
        free(conf->saved_nics);
 }
 
+static inline void lxc_clear_aliens(struct lxc_conf *conf)
+{
+       struct lxc_list *it,*next;
+
+       lxc_list_for_each_safe(it, &conf->aliens, next) {
+               lxc_list_del(it);
+               free(it->elem);
+               free(it);
+       }
+}
+
 static inline void lxc_clear_includes(struct lxc_conf *conf)
 {
        struct lxc_list *it,*next;
index 53590bc659a46436d141c9d804f7c6fe75906c83..ace1da09eb242f25d83b5a3059cc14d3cef56180 100644 (file)
@@ -342,6 +342,8 @@ struct lxc_conf {
 
        /* list of included files */
        struct lxc_list includes;
+       /* config entries which are not "lxc.*" are aliens */
+       struct lxc_list aliens;
 };
 
 int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
index 2ab3fcb73a46ac547d9aa1fce394b6a625ce7d98..32f08c7fb4493285dd34ce9f637b6b153b70a407 100644 (file)
@@ -1632,6 +1632,31 @@ static int config_utsname(const char *key, const char *value,
        return 0;
 }
 
+static int store_martian_option(char *line, void *data)
+{
+       struct lxc_conf *conf = data;
+       char *str;
+       struct lxc_list *list;
+       size_t len = strlen(line);
+
+       if (!conf->unexpanded)
+               return 0;
+       list = malloc(sizeof(*list));
+       if (!list)
+               return -1;
+       lxc_list_init(list);
+       str = malloc(len+1);
+       if (!str) {
+               free(list);
+               return -1;
+       }
+       strncpy(str, line, len);
+       len[len] = '\0';
+       list->elem = str;
+       lxc_list_add_tail(&conf->aliens, list);
+       return 0;
+}
+
 static int parse_line(char *buffer, void *data)
 {
        struct lxc_config_t *config;
@@ -1656,12 +1681,16 @@ static int parse_line(char *buffer, void *data)
 
        line += lxc_char_left_gc(line, strlen(line));
 
-       /* martian option - ignoring it, the commented lines beginning by '#'
-        * fall in this case
-        */
-       if (strncmp(line, "lxc.", 4))
+       /* ignore comments */
+       if (line[0] == '#')
                goto out;
 
+       /* martian option - save it in the unexpanded config only */
+       if (strncmp(line, "lxc.", 4)) {
+               ret = store_martian_option(line, data);
+               goto out;
+       }
+
        ret = -1;
 
        dot = strstr(line, "=");
@@ -2258,10 +2287,16 @@ void write_config(FILE *fout, struct lxc_conf *c)
        struct lxc_list *it;
        int i;
 
+       /* first write any includes */
        lxc_list_for_each(it, &c->includes) {
                fprintf(fout, "lxc.include = %s\n", (char *)it->elem);
        }
 
+       /* now write any aliens */
+       lxc_list_for_each(it, &c->aliens) {
+               fprintf(fout, "%s\n", (char *)it->elem);
+       }
+
        if (c->fstab)
                fprintf(fout, "lxc.mount = %s\n", c->fstab);
        lxc_list_for_each(it, &c->mount_list) {