<div dir="ltr">And I have other question. Generally we wonder what will be better design for monitoring systemd services<div>1.)</div><div>- add-match to ActiveState</div><div>- subscribe to systemd1.Manager</div><div>- then we have to start in separate thread some infinitive-loop with <span style="color:rgb(0,0,0);white-space:pre-wrap">sd_bus_wait() and sd_bus_process() (*)</span></div><div><font color="#000000"><span style="white-space:pre-wrap">2.)</span></font></div><div><font color="#000000"><span style="white-space:pre-wrap">- asking for example each 5s all services with the aid of method sd_bus_get_property about ActiveState. None additional thread is required in our case as timer when expires send notification to existed infinity while loop from current handler.</span></font></div><div><font color="#000000"><span style="white-space:pre-wrap"><br></span></font></div><div><div><font color="#000000"><span style="white-space:pre-wrap">I wonder which solution occupy more processor. From the first glance it seems like second one, because there might be too much unnecessary communication through the bus in order to get to know about systemd service states.</span></font></div><div><font color="#000000"><span style="white-space:pre-wrap">However take care that here (*) we have to have some infinity while loop probably in separate thread which will block thread waiting for signals from systemd. As far as timers are concerned in 2nd solution none additional thread is required. Is it possible somehow in 1.) not to have additional thread in order to receive signal from systemd?</span></font></div><div><font color="#000000"><span style="white-space:pre-wrap">Moreover 2nd solution seems to be better in case when systemd1.Manager fail at all (will be killed). In 2nd solution we will get to know it immediately as there will be none response on sd_bus_get_property. In 1.) solution we won't know that, thinking services are in active state.</span></font></div><div><font color="#000000"><span style="white-space:pre-wrap">Thanks in advance for your opinions.</span></font></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-01-16 15:41 GMT+01:00 Tomasz Michalski <span dir="ltr"><<a href="mailto:tmichalski23@gmail.com" target="_blank">tmichalski23@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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.<wbr>systemd1',"</div><div> "interface='org.freedesktop.<wbr>DBus.Properties',"</div><div> "member='PropertiesChanged',"</div><div> "arg0='org.freedesktop.<wbr>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.<wbr>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_<wbr>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(<wbr>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>
</blockquote></div><br></div>