<div dir="ltr"><div>Hi</div><div>I am in the middle of implementation monitor for getting states from services. I have some question to my current implementation.</div><div>My current implementation is:<br></div><div><br></div><div>void main()</div><div>{</div><div>.....</div><div><div> r = sd_bus_add_match(&bus,</div><div> NULL,</div><div> "type='signal',"</div><div> "sender='org.freedesktop.systemd1',"</div><div> "interface='org.freedesktop.DBus.Properties',"</div><div> "member='PropertiesChanged',"</div><div> "arg0='org.freedesktop.systemd1.Unit'",</div><div> propertiesChangedHandler,</div><div> NULL); //user data*/</div><div> if (r < 0)</div><div> {</div><div> fprintf(stderr, "Failed to add match for PropertiesChanged", strerror(-r));</div><div> goto finish;</div><div> } </div></div><div><br></div><div><pre style="border:0px;margin-top:0px;margin-bottom:0px"><font color="#000000"> 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;
}<br></font></pre></div><div>... </div><div>}</div><div><br></div><div>Handler:</div><div><div>int propertiesChangedHandler(sd_bus_message *message, void *userdata, sd_bus_error *error) </div><div>{</div><div> const char *data;</div><div> const char *path;</div><div> int r = 0;</div><div> </div><div> if(!message)</div><div> printf("Empty message provided\n");</div><div> </div><div> path = sd_bus_message_get_path(message);</div><div> if (!path)</div><div> {</div><div> printf("Empty message provided\n");</div><div> return 0;</div><div> }</div><div><br></div><div> r = sd_bus_message_read(message, "s", &data); //here problem with parsing ActiveState,SubState</div><div> if (r < 0) </div><div> {</div><div> fprintf(stderr, "Failed to parse response message: %s\n", strerror(-r));</div><div> return 0;</div><div> }</div><div>}</div></div><div><br></div><div><br></div><div>Question:</div><div>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:</div><div>"arg1='ActiveState'",<br></div><div>"arg2='SubState'"<br></div><div>?</div><div><br></div></div>