[systemd-devel] Returning a struct from an sd-bus method

Niall Murphy rinvix at gmail.com
Thu Aug 23 14:52:38 UTC 2018


Hi,

I'm trying to return a struct from an sdbus method. I followed the simple
example of a service at
http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html. I then created
a simple method as follows:

struct pack {
    int x;
    int y;
};

static int foo(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
    struct pack s;
    s.x = 1;
    s.y = 2;
    return sd_bus_reply_method_return(m, "(xx)", s);
}

static const sd_bus_vtable vtable[] = {
        SD_BUS_VTABLE_START(0),
        SD_BUS_METHOD("foo", "", "(xx)", foo, SD_BUS_VTABLE_UNPRIVILEGED),
        SD_BUS_VTABLE_END
};

The rest of the service is as in the example. When I run the service and
call foo with busctl I get garbage:
(xx) 8589934593 140731098591648

Can someone point me to what I am doing wrong?

Thanks,
Niall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20180823/a035038e/attachment.html>


More information about the systemd-devel mailing list