[systemd-devel] How to unlock a blocking sd_bus_wait() call

Iñigo Martínez inigomartinez at gmail.com
Thu Jan 7 09:52:47 PST 2016


I am going to face the same scenario in short, due to the need to do
D-Bus calls in the main thread and, as it's your case, serve D-Bus
calls in another thread.

I still have to think a bit about how to do it in my case, but here
are some ideas.

- sd_bus_wait calls to bus_poll that does the poll using ppoll[0], so
you could interrupt it by sending a signal[1].
- I'm not sure if ppoll is a cancellation point (poll is in the
list[2], but not ppoll), but in that case, you could push a clean
function (close_bus) using[3] pthread_cleanup_push, so once the thread
is cancelled, the bus is closed.
- You could call to sd_bus_open_system from the thread 1, that creates
this D-Bus serving thread 2, pass the bus connection from thread 1 to
thread 2, cancel the thread 2 whenever you want from thread 1, and
finally unref/close the bus in the thread 1.

As I said, just some ideas... probably there are better ones...

Best regards,

[0] https://github.com/systemd/systemd/blob/master/src/libsystemd/sd-bus/sd-bus.c#L2876
[1] http://man7.org/linux/man-pages/man3/pthread_kill.3.html
[2] https://www.linux.com/learn/docs/man/pthreads7#lbAG
[3] http://man7.org/linux/man-pages/man3/pthread_cleanup_push.3.html


2016-01-07 14:49 GMT+01:00 Federico Di Pierro <nierro92 at gmail.com>:
> Hi!
> I'm trying to understand if there's a way to properly unlock a sd_bus_wait()
> blocking call, as i need the thread where the call is performed to leave.
> The cycle is something like:
>
> while (!quit) {
>          r = sd_bus_process(signal_bus, NULL);
>          if (r > 0) {
>                continue;
>          }
>          r = sd_bus_wait(signal_bus, (uint64_t) -1);
>          if (r < 0) {
>                 break;
>          }
>    }
> close_bus();
> pthread_exit(NULL);
>
> The quit status is changed elsewhere.
> Is there a way to achieve this thing?
>
> Thank you very much for your time!
> Federico
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
>


More information about the systemd-devel mailing list