Fwd: connect to session bus from root app
Simon McVittie
simon.mcvittie at collabora.co.uk
Fri Apr 17 05:22:46 PDT 2015
On 16/04/15 23:02, Sergei Lopatin wrote:
> I try to connect to user session bus from my Qt root app. Unfortunately,
> I can't do this right.
The incorrect thing you're doing is trying to do that layering violation
in the first place. "Larger"/"lower-level" things (system services)
should never connect to "smaller"/"higher-level" things (user sessions);
if they should interact, then the user session should connect to system
services, not the other way round.
> FYI: I need root privileges to access system devices directly and
> session bus to set inhibitions preventing sleep/idle.
Preventing sleep is a system function. You could check how things on the
session bus would do that (on modern Linux the answer is usually "by
talking to logind, which is a system service"), and do that directly.
If you need a session app (which does things like preventing
lock-on-idle) to use devices or other system-level things, the
recommended way to do that is to have a system service that grants
limited, safe access to those things, then make your session app use
that system service.
Some real-world examples (these are GNOME-centric because that's what I
use, but similar things happen in other environments):
GNOME Shell (a GUI in the user session) uses NetworkManager (a system
service) to configure networking (a privileged system-level action)
GNOME Shell also uses BlueZ (a system service) to manipulate Bluetooth
devices (a privileged system-level action)
GNOME Software (a GUI in the user session) uses PackageKit (a system
service) to install packages (a privileged system-level action)
gnome-disks (a GUI in the user session) uses gvfs (a service in the user
session) which uses udisks2 (a system service) to manipulate disk
devices (a privileged system-level action)
--
Simon McVittie
Collabora Ltd. <http://www.collabora.com/>
More information about the dbus
mailing list