Re: Check whether a dbus caller is still alive

Bastien Nocera <[email protected]>
Newsgroups gmane.comp.freedesktop.dbus
Message-ID <[email protected]>
On Sun, 2017-10-01 at 14:25 +0100, 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.
> 
> 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
> flexibility.

g_bus_watch_name () and associated (see "Watching Bus Names" page in
the GIO API docs) is what you want.

This is an example of a service which implements the Freedesktop
Inhibit spec by calling gnome-session's API:
https://git.gnome.org//browse/gnome-settings-daemon/tree/plugins/screensaver-proxy/gsd-screensaver-proxy-manager.c

As gnome-session isn't watching the real caller, we need to make sure
our long running proxy disables the inhibition if the real client goes
away. This is done using a watch on the peer name.

HTH
_______________________________________________
dbus mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dbus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.