[systemd-devel] [WIP][PATCH 3/3] sd-bus: why not allow entering containers with unknown contents?

Lennart Poettering lennart at poettering.net
Mon Oct 28 12:02:10 PDT 2013


On Sun, 20.10.13 23:59, Tom Gundersen (teg at jklm.no) wrote:

Hmm, we could probably allow this in
sd_bus_message_enter_container() directly, so that this extra work
becomes unnecessary. So far I tried to push people to always specify
what they expect as safety check, but I figure in this case this is
pointless. So I guess we could allow that if the user passes in a 0 type
and/or a NULL contents value we skip that part of the check. 

Patch welcome. ;-)

I also added this to the TODO list for now though.

> ---
>  src/machine/machinectl.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
> index ba0ceb7..5731247 100644
> --- a/src/machine/machinectl.c
> +++ b/src/machine/machinectl.c
> @@ -334,6 +334,21 @@ static int print_property(const char *name, sd_bus_message *reply) {
>          return 0;
>  }
>  
> +static int sd_bus_message_enter_unknown_container(sd_bus_message *message, char type) {
> +        const char *contents;
> +        int r;
> +
> +        r = sd_bus_message_peek_type(reply, NULL, &contents);
> +        if (r < 0)
> +                return r;
> +
> +        r = sd_bus_message_enter_contanire(reply, type, contents);
> +        if (r < 0)
> +                return r;
> +
> +        return 0;
> +}
> +
>  static int show_one(const char *verb, sd_bus *bus, const char *path, bool show_properties, bool *new_line) {
>          _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
>          _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
> @@ -378,11 +393,7 @@ static int show_one(const char *verb, sd_bus *bus, const char *path, bool show_p
>                  if (r < 0)
>                          goto fail;
>  
> -                r = sd_bus_message_peek_type(reply, NULL, &contents);
> -                if (r < 0)
> -                        goto fail;
> -
> -                r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_VARIANT, contents);
> +                r = sd_bus_message_enter_unknown_container(reply, SD_BUS_TYPE_VARIANT);
>                  if (r < 0)
>                          goto fail;
>  


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list