Check whether a dbus caller is still alive

David Llewellyn-Jones david at flypig.co.uk
Sun Oct 1 19:55:28 UTC 2017


On 01/10/17 18:28, Thiago Macieira wrote:
> On Sunday, 1 October 2017 06:25:51 PDT David Llewellyn-Jones wrote:
>> Hi,
>>
>> 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.
> 
> Sure. You can watch the NameOwnerChanged signal to see if that particular 
> unique connection ID changes owner to "", indicating that it disconnected.

Thank you Thiago. I can now catch the name changes using

g_dbus_connection_signal_subscribe(connection, "org.freedesktop.DBus",
"org.freedesktop.DBus", "NameOwnerChanged", "/org/freedesktop/DBus",
NULL, G_DBUS_SIGNAL_FLAGS_NONE, signal_callback, user_data, NULL);

and I see separate signals when the owner connects and dies for each
invocation.

However, the signal gives me a connection, which is the same for each
invocation. I can't see a way to tie the owner to the
GDBusMethodInvocation instance.

Any suggestions?

David
-- 
Website: http://www.flypig.co.uk


More information about the dbus mailing list