[systemd-devel] sd-bus delayed reply

Giacinto Cifelli gciofono at gmail.com
Thu Jan 31 18:58:09 UTC 2019


Hi Lennart,
On Mon, Jan 28, 2019 at 1:07 PM Lennart Poettering
<lennart at poettering.net> wrote:
>
> On Mo, 28.01.19 14:00, Jean Valjean (valjean.jean1802 at gmail.com) wrote:
> 65;5403;1c
> > Can I, in principle, register objects and interfaces with
> > sd_bus_add_object_vtable like in
> > http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html
> > and in handler function, take a copy, of a reference to message
> > object, to global variable and use it later with
> > sd_bus_reply_method_return?
> > I tried to do that. But it seems, that when handler function returns,
> > it sends an error message to calling client if
> > sd_bus_reply_method_return
> > was not called inside handler.
>
> Depends on what you return in the handler function:
>
> 1. Returning < 0 means sd-bus will generate an automatic error reply
>    for you, taking the returned value as negative errno (or looking
>    into the sd_bus_error struct passed to you, which takes
>    precedence).
>
> 2. Returning 0 means it will generate an automatic response suggesting
>    that the method call was not handled.
>
> 3. Returning > 0 means however that you handled the message, and
>    sd-bus will not generate any reply.

I am using the same technique and works fine for methods, but I have
problems with the properties:
   SD_BUS_WRITABLE_PROPERTY(property, signature, get_property,
set_property, 0, SD_BUS_VTABLE_UNPRIVILEGED)

in the file: bus-object.c, the function
property_get_set_callbacks_run, executes this call to my set_property:
                r = invoke_property_set(bus, slot, c->vtable, m->path,
c->interface, c->member, m, u, &error);
                if (r < 0)
                        return bus_maybe_reply_error(m, r, &error);
              [...]
        r = sd_bus_send(bus, reply, NULL);

with no possibility for a delayed answer.

In the code above, I would need the following:
                if (r < 0)
                        return bus_maybe_reply_error(m, r, &error);
+              if (r > 0)
+                      return 0;

for it to work.
Or is there another way?

thank you,
Giacinto

>
> Hence, just exit your function with "return 1" if you don't want any
> automatic reply to be generated and all is good.
>
> (The above applies to all msg handler functions in sd-bus
> basically. The reason for doing #2 is that if you install filter
> functions that are called on every single incoming msg you can decide
> by returning 0 or 1 whether further filter functions shall be called,
> or not)
>
> Lennart
>
> --
> Lennart Poettering, Red Hat
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list