[systemd-devel] sd-bus delayed reply

Lennart Poettering lennart at poettering.net
Mon Jan 28 12:07:48 UTC 2019


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.

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


More information about the systemd-devel mailing list