How to interact with existing dbus session through sudo?

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Mar 19 04:37:13 PDT 2014


On 18/03/14 21:57, Louise Baldwin wrote:
> I don't understand why the dbus developers would want to prevent cron or
> sudo for a user from being able to interact with dbus-enabled
> applications for that user.

We don't specifically want to *prevent* it, but it's awkward to do (you
always have to ask the question "which session?") and there is usually a
better way to achieve the same result.

> All I want to do is set user Louise's Pidgin instant messenger status to
> "offline" using purple-remote immediately prior to suspending the
> computer. If I don't do this, the instant messenger handle will appear
> online to my buddies even though I will no longer be connected

A better way to do this is for an autostarted process inside your
session to watch the system bus for notifications about system events
(such as "about to suspend"), and ping Pidgin on the session bus (either
by executing purple-remote, or by using the same session D-Bus API that
purple-remote does).

With modern system services such as systemd-logind, it should even be
possible to make this work reliably, by delaying suspend until either
Pidgin reports that it has disconnected, or a (short) timeout is reached
- this wasn't possible in older system services that sent "about to
suspend" notifications, but couldn't wait for things to disconnect, so
if you were unlucky, the TCP disconnection didn't actually take effect
until you had already suspended and resumed.

telepathy-mission-control does the Telepathy equivalent of what you're
looking for (this is in C, but it should be implementable in Python or
similar):
<http://cgit.freedesktop.org/telepathy/telepathy-mission-control/tree/src/connectivity-monitor.c>

    S



More information about the dbus mailing list