Skip to content

Commit

Permalink
confile: cleanup parse_line()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Dec 8, 2020
1 parent 8f20444 commit 2e373df
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/lxc/confile.c
Expand Up @@ -2799,10 +2799,11 @@ struct parse_line_conf {

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;
struct lxc_config_t *config;
int ret = 0;
int ret;
char *dup = buffer;
struct parse_line_conf *plc = data;

Expand All @@ -2817,34 +2818,30 @@ static int parse_line(char *buffer, void *data)
*/
linep = line = strdup(dup);
if (!line)
return -1;
return ret_errno(ENOMEM);

if (!plc->from_include) {
ret = append_unexp_config_line(line, plc->conf);
if (ret < 0)
goto on_error;
return ret;
}

if (empty_line)
goto on_error;
return 0;

line += lxc_char_left_gc(line, strlen(line));

/* ignore comments */
if (line[0] == '#')
goto on_error;
return 0;

/* martian option - don't add it to the config itself */
if (strncmp(line, "lxc.", 4))
goto on_error;

ret = -1;
return 0;

dot = strchr(line, '=');
if (!dot) {
ERROR("Invalid configuration line: %s", line);
goto on_error;
}
if (!dot)
return log_error_errno(-EINVAL, EINVAL, "Invalid configuration line: %s", line);

*dot = '\0';
value = dot + 1;
Expand All @@ -2866,17 +2863,10 @@ static int parse_line(char *buffer, void *data)
}

config = lxc_get_config(key);
if (!config) {
ERROR("Unknown configuration key \"%s\"", key);
goto on_error;
}

ret = config->set(key, value, plc->conf, NULL);

on_error:
free(linep);
if (!config)
return log_error_errno(-EINVAL, EINVAL, "Unknown configuration key \"%s\"", key);

return ret;
return config->set(key, value, plc->conf, NULL);
}

static struct new_config_item *parse_new_conf_line(char *buffer)
Expand Down

0 comments on commit 2e373df

Please sign in to comment.