[systemd-devel] Monitoring services start event from kdbus with sd-bus API
Mantas Mikulėnas
grawity at gmail.com
Tue Jun 30 02:26:54 PDT 2015
First, are you actually switching your bus connection to monitor mode? In
kdbus (and probably even in future DBus) there is a distinct monitor mode
which must be enabled to capture other peers' bus traffic. Adding a match
is not enough for that.
Second, your approach won't work anyway. There *won't be* method_calls for
services that are started as dependencies, there won't be method calls for
socket-activated services, there won't be method calls for DBus-activated
services, there probably won't be even a single Start call during the
entire boot process. Systemd won't bother calling itself over DBus for that.
Instead, why not use the *signals* that systemd sends, for exactly such
purposes? You'll need to call Subscribe() to enable them.
See also what Plymouth does for its splash screen.
On Tue, Jun 30, 2015, 12:15 Thomas Schmidt <t.schmidt at md-network.de> wrote:
> Hello,
> for an embedded project I’m implementing a bootsplash application which
> should as well display service names are starting.
> This is based on kdbus and uses the sd-bus API to communicate with systemd
> (for example boot process percentage property is polled).
> Now I try to monitor the kdbus (system bus) to capture the events which
> indicate that a service was started. (works very well for testing with
> "busctl monitor“ tool).
> I assumed that the method_call „StartUnit“ would be a good indicator, so I
> tried to monitor for those messages by using following code (shortened and
> only significant parts copied here):
>
> -.-.-.-.-.-.-.-.-.-.-. schnipp -.-.-.-.-.-.-.-.-.-.-
>
> r = sd_bus_open_system(&bus);
> …
> r = sd_bus_add_match(bus, NULL, "", do_something_callback, NULL); /*
> should not filter anything, I expect it triggers on any message */
> …
>
> for (;;) {
> sd_bus_message *m = NULL;
>
> r = sd_bus_process(bus, &m);
> if (r < 0) {
> fprintf(stderr, "Failed to process bus: %s\n",
> strerror(-r));
> goto finish;
> }
>
> if (r > 0) /* we processed a request, try to process
> another one, right-away */
> continue;
>
> /* Wait for the next request to process */
> r = sd_bus_wait(bus, (uint64_t) -1);
> if (r < 0) {
> fprintf(stderr, "Failed to wait on bus: %s\n",
> strerror(-r));
> goto finish;
> }
>
> }
> …
>
> -.-.-.-.-.-.-.-.-.-.-. schnapp -.-.-.-.-.-.-.-.-.-.-
>
> The interesting thing is that this code only sees „signal“ type messages
> - but not any other like „method_call“.
>
> I did extensive testing, tried different code variants, for example by
> processing "sd_bus_message *m“ directly in the for loop with
> „sd_bus_message_is_method_call“ - but the effect is the same I don’t get
> „method_call“ as an event.
>
> Is there any suggestion what could be the reason ? (is that generally the
> right way what I try here to do ?)
>
> Many thanks for any feedback which points me to the right direction
> Kind Regards
> Thomas Schmidt
>
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20150630/016aa69d/attachment.html>
More information about the systemd-devel
mailing list