[systemd-devel] [PATCH] config_parse_exec_mount_flags: get rid of unnecessary copy

Lennart Poettering lennart at poettering.net
Wed Feb 11 04:08:26 PST 2015


On Fri, 06.02.15 16:46, Maciej Wereski (m.wereski at partner.samsung.com) wrote:

> ---
>  src/core/load-fragment.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
> index 90bf563..6108d12 100644
> --- a/src/core/load-fragment.c
> +++ b/src/core/load-fragment.c
> @@ -1203,21 +1203,15 @@ int config_parse_exec_mount_flags(const char *unit,
>          assert(data);
>  
>          FOREACH_WORD_SEPARATOR(word, l, rvalue, ", ", state) {
> -                _cleanup_free_ char *t;
> -
> -                t = strndup(word, l);
> -                if (!t)
> -                        return log_oom();
> -
> -                if (streq(t, "shared"))
> +                if (strneq(word, "shared", l))
>                          flags = MS_SHARED;
> -                else if (streq(t, "slave"))
> +                else if (strneq(word, "slave", l))
>                          flags = MS_SLAVE;
> -                else if (streq(word, "private"))
> +                else if (strneq(word, "private", l))
>                          flags = MS_PRIVATE;

This optimization is not valid.

If 'word' is set to "sh", then l will be 2, and strneq(word, "shared",
2) is true, but we don't actually want to allow such abbreviations!

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list