confile: cleanup parse_line()

parent d6f18b12
...@@ -2593,10 +2593,11 @@ struct parse_line_conf { ...@@ -2593,10 +2593,11 @@ struct parse_line_conf {
static int parse_line(char *buffer, void *data) static int parse_line(char *buffer, void *data)
{ {
char *dot, *key, *line, *linep, *value; __do_free char *linep = NULL;
char *dot, *key, *line, *value;
bool empty_line; bool empty_line;
struct lxc_config_t *config; struct lxc_config_t *config;
int ret = 0; int ret;
char *dup = buffer; char *dup = buffer;
struct parse_line_conf *plc = data; struct parse_line_conf *plc = data;
...@@ -2611,34 +2612,30 @@ static int parse_line(char *buffer, void *data) ...@@ -2611,34 +2612,30 @@ static int parse_line(char *buffer, void *data)
*/ */
linep = line = strdup(dup); linep = line = strdup(dup);
if (!line) if (!line)
return -1; return ret_errno(ENOMEM);
if (!plc->from_include) { if (!plc->from_include) {
ret = append_unexp_config_line(line, plc->conf); ret = append_unexp_config_line(line, plc->conf);
if (ret < 0) if (ret < 0)
goto on_error; return ret;
} }
if (empty_line) if (empty_line)
goto on_error; return 0;
line += lxc_char_left_gc(line, strlen(line)); line += lxc_char_left_gc(line, strlen(line));
/* ignore comments */ /* ignore comments */
if (line[0] == '#') if (line[0] == '#')
goto on_error; return 0;
/* martian option - don't add it to the config itself */ /* martian option - don't add it to the config itself */
if (strncmp(line, "lxc.", 4)) if (strncmp(line, "lxc.", 4))
goto on_error; return 0;
ret = -1;
dot = strchr(line, '='); dot = strchr(line, '=');
if (!dot) { if (!dot)
ERROR("Invalid configuration line: %s", line); return log_error_errno(-EINVAL, EINVAL, "Invalid configuration line: %s", line);
goto on_error;
}
*dot = '\0'; *dot = '\0';
value = dot + 1; value = dot + 1;
...@@ -2660,17 +2657,10 @@ static int parse_line(char *buffer, void *data) ...@@ -2660,17 +2657,10 @@ static int parse_line(char *buffer, void *data)
} }
config = lxc_get_config(key); config = lxc_get_config(key);
if (!config) { if (!config)
ERROR("Unknown configuration key \"%s\"", key); return log_error_errno(-EINVAL, EINVAL, "Unknown configuration key \"%s\"", key);
goto on_error;
}
ret = config->set(key, value, plc->conf, NULL);
on_error:
free(linep);
return ret; return config->set(key, value, plc->conf, NULL);
} }
static struct new_config_item *parse_new_conf_line(char *buffer) static struct new_config_item *parse_new_conf_line(char *buffer)
......
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