Re: [systemd-devel] sd-bus signal callback return value

2020-03-31 Thread Lennart Poettering
On Di, 24.03.20 21:43, Stanislav Angelovič (angelovi...@gmail.com) wrote:

> Hi folks,
>
> Please, what is the difference in sd-bus behavior when my D-Bus signal
> callback returns a zero return value versus a positive return value?

positive means "I processed the message, stop processing it further".

negative means "This message did not match my criteria, pass it to any
other callback that might be interested.

Basically, an incoming msg can match against multiple handlers, in
particular if you combine multiple instances of sd_bus_add_filter()
and sd_bus_add_match(). sd-bus will call them in the order you
registered them in, and will pass the incoming signal to each one in
turn as long as each returns 0. It stops when one returns > 0.

In most cases you want to return 0, to allow everyone who wants have a
look at the message. You'd return > 0 only if you want actively filter
a message so that noone else can see it, maybe to hide stuff from
other parts of the program if that's your kind of thing.

> And what's the difference between those return values in D-Bus method
> callback, D-Bus async method reply callback, D-Bus property get callback,
> and D-Bus property set callback?

it's always the same: whether to traverse the installed handlers
further.

Note that for method call handlers you typically want to return > 0
btw, because if you return 0 and sd-bus reaches the end of the list of
registered handlers it assumes noone was interested and synthesizes a
"NoSuchMethod" error reply.

> Which shall I return in normal cases? Zero?

when handling signals: zero. when handling incoming method calls: one.

Lennart

--
Lennart Poettering, Berlin
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] sd-bus signal callback return value

2020-03-28 Thread Daan De Meyer
Hi,

I've opened a pull request to clarify the return values of the callbacks
and their effect: https://github.com/systemd/systemd/pull/15253. It's not
complete yet but the idea is to add answers for all your questions to the
docs.

Regards,

Daan

On Tue, 24 Mar 2020 at 21:44, Stanislav Angelovič 
wrote:

> Hi folks,
>
> Please, what is the difference in sd-bus behavior when my D-Bus signal
> callback returns a zero return value versus a positive return value?
>
> And what's the difference between those return values in D-Bus method
> callback, D-Bus async method reply callback, D-Bus property get callback,
> and D-Bus property set callback?
>
> Which shall I return in normal cases? Zero?
>
> Thanks a lot in advance for your response... Take care & stay healthy,
>
> Stanislav.
>
> ___
> systemd-devel mailing list
> systemd-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel