Check whether a dbus caller is still alive

David Llewellyn-Jones david at
Sun Oct 1 13:25:51 UTC 2017


I have an application that connects to a systemd service via the system
bus. The application makes a synchronous call which blocks, until the
service responds, which may take some time.

My concern is that the application may get closed before the service
responds. Is there any way for the service to check whether the
invocation is still valid? If the application closes, I'd like the
service to stop the long-running operation.

For context, the service uses gdbus and a GMainLoop. When it receives an
invocation a function like this gets called:

static gboolean on_handle_function(FlypigInterface * object,
GDBusMethodInvocation * invocation, gint handle, gpointer user_data) {
    // ...perform long running task

Then, when it's done with the task, it calls something like this
(created by gdbus-codegen) to respond back to the application:

void flypig_interface_complete_function (
    FlypigInterface *object,
    GDBusMethodInvocation *invocation,
    gboolean success);

My constraints are that the application must be synchronous, so can't do
anything else while it's waiting, whereas the service has much more

Grateful for any suggestions.


More information about the dbus mailing list