[systemd-devel] [PATCH 2/2] hostnamectl: port to sd-bus

Kay Sievers kay at vrfy.org
Fri Nov 1 16:20:11 PDT 2013


On Wed, Oct 30, 2013 at 6:55 AM, Simon Peeters <peeters.simon at gmail.com> wrote:

> +#define foreach_dbus_property(r, bus, dest, object, error, reply, name, contents) \
> +        for (int _i = 0; _i < 3; _i++) \
> +                if (_i == 0) { \
> +                        r = sd_bus_call_method(bus, dest, object,\
> +                                        "org.freedesktop.DBus.Properties",\
> +                                        "GetAll", &error, &reply, "s", "");\
> +                        if (r < 0) {\
> +                                log_error("Could not get properties: %s", bus_error_message(&error, -r));\
> +                                break;\
> +                        }\
> +                        r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "{sv}");\
> +                        if (r < 0) goto CATENATE(fail,__LINE__); \
> +                } else if (_i == 2) { \
> +                        r = sd_bus_message_exit_container(reply);\
> +                        if (r < 0) goto CATENATE(fail,__LINE__); \
> +                        break;\
> +        CATENATE(fail,__LINE__):\
> +                        log_error("Failed to parse reply: %s", strerror(-r)); \
> +                        r = -EIO;\
> +                        break;\
> +                } else \
> +                        while ((r = sd_bus_message_enter_container(reply,\
> +                                        SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0)\
> +                                for (int _j = 0; _j < 3; _j++) \
> +                                        if (_j == 0) {\
> +                                                if (r < 0) goto CATENATE(fail,__LINE__);\
> +                                                r = sd_bus_message_read(reply, "s", &(name));\
> +                                                if (r < 0) goto CATENATE(fail,__LINE__);\
> +                                                r = sd_bus_message_peek_type(reply, NULL, &(contents));\
> +                                                if (r < 0) goto CATENATE(fail,__LINE__);\
> +                                                r = sd_bus_message_enter_container(reply,\
> +                                                                SD_BUS_TYPE_VARIANT, contents);\
> +                                                if (r < 0) goto CATENATE(fail,__LINE__);\
> +                                        } else if (_j ==2) {\
> +                                                r = sd_bus_message_exit_container(reply);\
> +                                                if (r < 0) goto CATENATE(fail,__LINE__);\
> +                                                r = sd_bus_message_exit_container(reply);\
> +                                                if (r < 0) goto CATENATE(fail,__LINE__);\
> +                                        } else
> +

Cool, but it's quite a bit too magical, I think. :)

But yeah, we should have something which makes GetAll easier. Now
about something like the attached patch?

Thanks,
Kay
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-bus-use-internal-helper-to-read-org.freedesktop.DBus.patch
Type: text/x-patch
Size: 17663 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20131102/5436c6f0/attachment-0001.bin>


More information about the systemd-devel mailing list