]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: do not write out trailing spaces
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 30 May 2017 01:19:26 +0000 (03:19 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 30 May 2017 16:43:03 +0000 (18:43 +0200)
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>
src/lxc/confile.c

index ddfc1563c001946940b86bdca6802edd97231beb..371b1737e18bea82ef111d03945e9692e3491fe8 100644 (file)
@@ -2951,10 +2951,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;