[systemd-devel] [PATCH] tmpfiles: port to unquote_many_words()

Ronny Chevalier chevalier.ronny at gmail.com
Mon Mar 9 11:14:22 PDT 2015


2015-03-09 18:51 GMT+01:00 daurnimator <quae at daurnimator.com>:

Hi,

> ---
>  TODO                    |  2 --
>  man/tmpfiles.d.xml      |  2 ++
>  src/tmpfiles/tmpfiles.c | 24 ++++++++++--------------
>  3 files changed, 12 insertions(+), 16 deletions(-)
>
> diff --git a/TODO b/TODO
> index 60efaaf..4d5e2b6 100644
> --- a/TODO
> +++ b/TODO
> @@ -226,8 +226,6 @@ Features:
>
>  * exponential backoff in timesyncd and resolved when we cannot reach a server
>
> -* tmpfiles: port to unquote_many_words(), similar to sysusers
> -
>  * unquote_many_words() should probably be used by a lot of code that
>    currently uses FOREACH_WORD and friends. For example, most conf
>    parsing callbacks should use it.
> diff --git a/man/tmpfiles.d.xml b/man/tmpfiles.d.xml
> index 4bd0fcf..c1c4a44 100644
> --- a/man/tmpfiles.d.xml
> +++ b/man/tmpfiles.d.xml
> @@ -118,6 +118,8 @@
>      d    /run/user   0755 root root 10d -
>      L    /tmp/foobar -    -    -    -   /dev/null</programlisting>
>
> +    <para>Fields can contain C-style escapes</para>
> +
>      <refsect2>
>        <title>Type</title>
>
> diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
> index 652fe5f..e6ee5b8 100644
> --- a/src/tmpfiles/tmpfiles.c
> +++ b/src/tmpfiles/tmpfiles.c
> @@ -1502,27 +1502,30 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
>                  {}
>          };
>
> -        _cleanup_free_ char *action = NULL, *mode = NULL, *user = NULL, *group = NULL, *age = NULL, *path = NULL;
> +        _cleanup_free_ char *action = NULL, *mode = NULL, *user = NULL, *group = NULL, *age = NULL, *path = NULL, *argument = NULL;
>          _cleanup_(item_free_contents) Item i = {};
>          ItemArray *existing;
>          Hashmap *h;
> -        int r, c = -1, pos;
> +        int r, pos;
>          bool force = false, boot = false;
>
>          assert(fname);
>          assert(line >= 1);
>          assert(buffer);
>
> -        r = sscanf(buffer,
> -                   "%ms %ms %ms %ms %ms %ms %n",
> +        r = unquote_many_words(&buffer,
>                     &action,
>                     &path,
>                     &mode,
>                     &user,
>                     &group,
>                     &age,
> -                   &c);
> -        if (r < 2) {
> +                   &argument,
> +                   NULL);
> +        if (r < 0) {
> +                log_error_errno(r, "[%s:%u] Failed to parse line: %m", fname, line);
> +                return r;

You can directly use:
        return log_error_errno(r, ...);

> +        } else if (r < 2) {
>                  log_error("[%s:%u] Syntax error.", fname, line);
>                  return -EIO;
>          }
> @@ -1559,14 +1562,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
>                  return r;
>          }
>
> -        if (c >= 0)  {
> -                c += strspn(buffer+c, WHITESPACE);
> -                if (buffer[c] != 0 && (buffer[c] != '-' || buffer[c+1] != 0)) {
> -                        i.argument = unquote(buffer+c, "\"");
> -                        if (!i.argument)
> -                                return log_oom();
> -                }
> -        }
> +        i.argument = argument;
>
>          switch (i.type) {
>
> --
> 2.3.1
>
> _______________________________________________
> 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