[systemd-devel] [PATCH] continuation support in envinronment files

Michal Vyskocil mvyskocil at suse.cz
Fri Jan 11 06:03:36 PST 2013


support for a continuations lines escaped by backslash (\). All lines
ends on \ will be appended with a next one(s).

fixes https://bugs.freedesktop.org/show_bug.cgi?id=58083
---
 src/shared/util.c |   34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/shared/util.c b/src/shared/util.c
index 49b5844..f7270c4 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -778,6 +778,8 @@ int load_env_file(
                 char ***rl) {
 
         FILE *f;
+        char *b = NULL;
+        char *c = NULL;
         char **m = NULL;
         int r;
 
@@ -807,6 +809,31 @@ int load_env_file(
                 if (strchr(COMMENTS, *p))
                         continue;
 
+                if (endswith(p, "\\")) {
+                        *(p+strlen(p)-1) = '\0';
+
+                        if (!(c = strappend(b, p))) {
+                                r = log_oom();
+                                goto finish;
+                        }
+
+                        free(b);
+                        b = c;
+                        continue;
+                }
+
+                if (b) {
+
+                        if (!(c = strappend(b, p))) {
+                                r = log_oom();
+                                goto finish;
+                        }
+
+                        free(b);
+                        b = NULL;
+                        p = c;
+                }
+
                 if (!(u = normalize_env_assignment(p))) {
                         r = log_oom();
                         goto finish;
@@ -814,6 +841,7 @@ int load_env_file(
 
                 t = strv_append(m, u);
                 free(u);
+                free(c);
 
                 if (!t) {
                         r = log_oom();
@@ -833,6 +861,12 @@ finish:
         if (f)
                 fclose(f);
 
+        if (b) {
+                free(b);
+                log_error("Failed to parse environment file %s: premature end of file.", fname);
+                r = 0;
+        }
+
         strv_free(m);
 
         return r;
-- 
1.7.10.4



More information about the systemd-devel mailing list