[systemd-devel] How to add filter for ActiveState property and get to know for which object this property is?

Lennart Poettering lennart at poettering.net
Wed Jan 24 11:22:17 UTC 2018


On Di, 16.01.18 15:41, Tomasz Michalski (tmichalski23 at gmail.com) wrote:

> Handler:
> int propertiesChangedHandler(sd_bus_message *message, void *userdata,
> sd_bus_error *error)
> {
>     const char *data;
>     const char *path;
>     int r = 0;
> 
>     if(!message)
>         printf("Empty message provided\n");
> 
>     path = sd_bus_message_get_path(message);
>     if (!path)
>     {
>         printf("Empty message provided\n");
>         return 0;
>     }
> 
>     r = sd_bus_message_read(message, "s", &data); //here problem with
> parsing ActiveState,SubState

The PropertiesChanged signal sends a more complex data struct
back. For details see the D-Bus spec:

https://dbus.freedesktop.org/doc/dbus-specification.html

It's a bit nasty to parse that out, but doable.

> Question:
> How to narrow down filter? In the above examples the handler will be
> triggered by any property change. I am only interested in ActiveState,
> eventually SubState trigger. Should I add in sd_bus_add_match:
> "arg1='ActiveState'",
> "arg2='SubState'"
> ?

Unfortunately D-bus does not allow such finegrained matches. You
cannot look inside of arrays or dicts with them.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list