[systemd-devel] How to add filter for ActiveState property and get to know for which object this property is?
Tomasz Michalski
tmichalski23 at gmail.com
Tue Jan 16 14:41:11 UTC 2018
Hi
I am in the middle of implementation monitor for getting states from
services. I have some question to my current implementation.
My current implementation is:
void main()
{
.....
r = sd_bus_add_match(&bus,
NULL,
"type='signal',"
"sender='org.freedesktop.systemd1',"
"interface='org.freedesktop.DBus.Properties',"
"member='PropertiesChanged',"
"arg0='org.freedesktop.systemd1.Unit'",
propertiesChangedHandler,
NULL); //user data*/
if (r < 0)
{
fprintf(stderr, "Failed to add match for PropertiesChanged",
strerror(-r));
goto finish;
}
r = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"Subscribe",
&error,
NULL,
NULL);
if (r < 0)
{
fprintf(stderr, "Failed to enable subscription: %s\n", strerror(-r));
//TO DO use also error code
return r;
}
...
}
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
if (r < 0)
{
fprintf(stderr, "Failed to parse response message: %s\n",
strerror(-r));
return 0;
}
}
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'"
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20180116/5577e443/attachment.html>
More information about the systemd-devel
mailing list