[systemd-devel] [PATCH 4/7] bus: rename sd_bus_get_property_{trivial, basic}

Lennart Poettering lennart at poettering.net
Thu Nov 7 10:15:35 PST 2013


On Thu, 07.11.13 13:49, Marc-Antoine Perennou (Marc-Antoine at Perennou.com) wrote:

This one is unfortunately not that easy. The reason this checks for
trivial and not basic types is that strings (which are basic, but not
trivial) are pointers in C. Usually we just return pointers into the
actual message. However, in this case the message is freed before
returning from sd_bus_get_property_trivial(), hence we cannot do
this. The alternative would be to allocate the thing from the heap and
return that, but that means the caller must know that and free it
afterwards. But those would be quite surprising semantics, especially
given that sd_bus_read_basic() does not require this, and the non-string
basic types require neither.

I can see though that it would be a good thing to read strings with an
easy call. I am hence going to add a separate call for this now, which
hopefully makes this a bit more understandable.

> ---
>  src/analyze/analyze.c                 | 2 +-
>  src/libsystemd-bus/bus-convenience.c  | 4 ++--
>  src/libsystemd-bus/libsystemd-bus.sym | 2 +-
>  src/systemd/sd-bus.h                  | 2 +-
>  4 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
> index 22bf076..522e618 100644
> --- a/src/analyze/analyze.c
> +++ b/src/analyze/analyze.c
> @@ -123,7 +123,7 @@ static int bus_get_uint64_property(sd_bus *bus, const char *path, const char *in
>          _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
>          int r;
>  
> -        r = sd_bus_get_property_trivial(
> +        r = sd_bus_get_property_basic(
>                          bus,
>                          "org.freedesktop.systemd1",
>                          path,
> diff --git a/src/libsystemd-bus/bus-convenience.c b/src/libsystemd-bus/bus-convenience.c
> index 0ccc259..db15fdd 100644
> --- a/src/libsystemd-bus/bus-convenience.c
> +++ b/src/libsystemd-bus/bus-convenience.c
> @@ -270,7 +270,7 @@ _public_ int sd_bus_get_property(
>          return 0;
>  }
>  
> -_public_ int sd_bus_get_property_trivial(
> +_public_ int sd_bus_get_property_basic(
>                  sd_bus *bus,
>                  const char *destination,
>                  const char *path,
> @@ -285,7 +285,7 @@ _public_ int sd_bus_get_property_trivial(
>          assert_return(bus, -EINVAL);
>          assert_return(isempty(interface) || interface_name_is_valid(interface), -EINVAL);
>          assert_return(member_name_is_valid(member), -EINVAL);
> -        assert_return(bus_type_is_trivial(type), -EINVAL);
> +        assert_return(bus_type_is_basic(type), -EINVAL);
>          assert_return(ptr, -EINVAL);
>          assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
>          assert_return(!bus_pid_changed(bus), -ECHILD);
> diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
> index 5eecfa1..01a0c8a 100644
> --- a/src/libsystemd-bus/libsystemd-bus.sym
> +++ b/src/libsystemd-bus/libsystemd-bus.sym
> @@ -141,7 +141,7 @@ global:
>          /* Convenience calls */
>          sd_bus_call_method;
>          sd_bus_get_property;
> -        sd_bus_get_property_trivial;
> +        sd_bus_get_property_basic;
>          sd_bus_set_property;
>          sd_bus_reply_method_return;
>          sd_bus_reply_method_error;
> diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
> index 48edc59..e38f4a4 100644
> --- a/src/systemd/sd-bus.h
> +++ b/src/systemd/sd-bus.h
> @@ -212,7 +212,7 @@ int sd_bus_message_rewind(sd_bus_message *m, int complete);
>  
>  int sd_bus_call_method(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *types, ...);
>  int sd_bus_get_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, sd_bus_message **reply, const char *type);
> -int sd_bus_get_property_trivial(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, char type, void *ptr);
> +int sd_bus_get_property_basic(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, char type, void *ptr);
>  int sd_bus_set_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, const char *type, ...);
>  int sd_bus_reply_method_return(sd_bus *bus, sd_bus_message *call, const char *types, ...);
>  int sd_bus_reply_method_error(sd_bus *bus, sd_bus_message *call, const sd_bus_error *e);


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list