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

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Sat Jan 12 13:35:52 PST 2013


On Fri, Jan 11, 2013 at 04:59:32PM +0100, Michal Vyskocil wrote:
> On Fri, Jan 11, 2013 at 04:25:16PM +0100, Zbigniew Jędrzejewski-Szmek wrote:
> > 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.
> 
> Sure - only end of lines should be removed - do we want to support unix
> ones, or both?
You mean LF or CRLF? Please no, just normal Unix eols.

> BTW: I've found some minor hickups in a code - empty lines got merged as
> well
> 
> BAR="some \
> 
> file"
> 
> will result to "some file" and the backslash before eof is threated as
> an error, where bash simply ignore it. I'd say systemd should behaves
> like a shell as much as possible, so I will sent a new patch.
> 
> > 
> > And then we'd need some documentation.
> 
> definitelly
Looking forward to your patch :)

Best,
Zbyszek

> Thanks
> Michal Vyskocil
> > 
> > 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


More information about the systemd-devel mailing list