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

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Fri Jan 11 07:25:16 PST 2013


On Fri, Jan 11, 2013 at 03:03:36PM +0100, Michal Vyskocil wrote:
> support for a continuations lines escaped by backslash (\). All lines
> ends on \ will be appended with a next one(s).
Looks very useful.

> 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, "\\")) {
Hm, since strstrip() is performed earlier, this means that lines
having whitespace _after_ the continuation symbol get merged. This
is different than what e.g. bash and python do. I think that diverging
like this is not wanted.

And then we'd need some documentation.

Also, endswith() returns the pointer to the beginning of the suffix,
so there's no need to run strlen() again.

> +                        *(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
> 
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
> 


More information about the systemd-devel mailing list