Commit 4184c3e1 by Serge Hallyn Committed by Stéphane Graber

Store alien config lines

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: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent f979ac15
...@@ -2690,6 +2690,7 @@ struct lxc_conf *lxc_conf_init(void) ...@@ -2690,6 +2690,7 @@ struct lxc_conf *lxc_conf_init(void)
lxc_list_init(&new->keepcaps); lxc_list_init(&new->keepcaps);
lxc_list_init(&new->id_map); lxc_list_init(&new->id_map);
lxc_list_init(&new->includes); lxc_list_init(&new->includes);
lxc_list_init(&new->aliens);
for (i=0; i<NUM_LXC_HOOKS; i++) for (i=0; i<NUM_LXC_HOOKS; i++)
lxc_list_init(&new->hooks[i]); lxc_list_init(&new->hooks[i]);
lxc_list_init(&new->groups); lxc_list_init(&new->groups);
...@@ -4365,6 +4366,17 @@ static void lxc_clear_saved_nics(struct lxc_conf *conf) ...@@ -4365,6 +4366,17 @@ static void lxc_clear_saved_nics(struct lxc_conf *conf)
free(conf->saved_nics); 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) static inline void lxc_clear_includes(struct lxc_conf *conf)
{ {
struct lxc_list *it,*next; struct lxc_list *it,*next;
......
...@@ -342,6 +342,8 @@ struct lxc_conf { ...@@ -342,6 +342,8 @@ struct lxc_conf {
/* list of included files */ /* list of included files */
struct lxc_list includes; 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, int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
......
...@@ -1632,6 +1632,31 @@ static int config_utsname(const char *key, const char *value, ...@@ -1632,6 +1632,31 @@ static int config_utsname(const char *key, const char *value,
return 0; 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) static int parse_line(char *buffer, void *data)
{ {
struct lxc_config_t *config; struct lxc_config_t *config;
...@@ -1656,12 +1681,16 @@ static int parse_line(char *buffer, void *data) ...@@ -1656,12 +1681,16 @@ static int parse_line(char *buffer, void *data)
line += lxc_char_left_gc(line, strlen(line)); line += lxc_char_left_gc(line, strlen(line));
/* martian option - ignoring it, the commented lines beginning by '#' /* ignore comments */
* fall in this case if (line[0] == '#')
*/
if (strncmp(line, "lxc.", 4))
goto out; 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; ret = -1;
dot = strstr(line, "="); dot = strstr(line, "=");
...@@ -2258,10 +2287,16 @@ void write_config(FILE *fout, struct lxc_conf *c) ...@@ -2258,10 +2287,16 @@ void write_config(FILE *fout, struct lxc_conf *c)
struct lxc_list *it; struct lxc_list *it;
int i; int i;
/* first write any includes */
lxc_list_for_each(it, &c->includes) { lxc_list_for_each(it, &c->includes) {
fprintf(fout, "lxc.include = %s\n", (char *)it->elem); 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) if (c->fstab)
fprintf(fout, "lxc.mount = %s\n", c->fstab); fprintf(fout, "lxc.mount = %s\n", c->fstab);
lxc_list_for_each(it, &c->mount_list) { lxc_list_for_each(it, &c->mount_list) {
......
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