Skip to content

Commit

Permalink
confile: do not write out trailing spaces
Browse files Browse the repository at this point in the history
So far do_append_unexp_config_line() wrote out a trailing space each time the
config item value was empty. This is a problem a) when we later on parse the
written out config file we need to remove trailing spaces and b).

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner authored and stgraber committed Jul 1, 2017
1 parent 08a4653 commit 5b52938
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lxc/confile.c
Expand Up @@ -2703,10 +2703,16 @@ void write_config(FILE *fout, struct lxc_conf *c)
bool do_append_unexp_config_line(struct lxc_conf *conf, const char *key, const char *v)
{
int ret;
size_t len = strlen(key) + strlen(v) + 4;
char *tmp = alloca(len);
size_t len;
char *tmp;

ret = snprintf(tmp, len, "%s = %s", key, v);
len = strlen(key) + strlen(v) + 4;
tmp = alloca(len);

if (config_value_empty(v))
ret = snprintf(tmp, len, "%s =", key);
else
ret = snprintf(tmp, len, "%s = %s", key, v);
if (ret < 0 || ret >= len)
return false;

Expand Down

0 comments on commit 5b52938

Please sign in to comment.