How to update GSettings from DBus without X display ?
smcv at collabora.com
Thu Mar 23 12:00:29 UTC 2017
On Tue, 21 Mar 2017 at 11:43:20 +0100, Alex ARNAUD wrote:
> I'm trying to update a GSettings user configuration from a Debian
> package. In the case where I apply the update without an X session I
> always obtain an error from DConf due to inability for its to find an X
I would like to re-word the error message in libdbus that mentions X11,
because it misleads people like you into thinking that D-Bus requires
X11. However, I'm not sure what replacement would be better.
Here is the situation, in terms that are too verbose for an error message:
To run things that use D-Bus and act per-user, you need to be able to
connect to that user's D-Bus session bus. dconf is one example of
something that is per-user (it is not *my system's* settings, but *my*
settings), and it uses the D-Bus session bus to coordinate access to a
single configuration store by multiple writers.
There are basically five ways you can get a session bus:
* distro/system infrastructure can start one that is shared between
all your concurrent login sessions while you log in to any graphical
or non-graphical session, like systemd does when you have the
dbus-user-session package installed
* distro infrastructure can start one while you log in to a graphical
session (in Debian, /etc/X11/Xsession.d does this)
* your desktop environment infrastructure can start one while you log in;
for example, I know GNOME does this if necessary, and KDE probably does
the same thing (but it should never be necessary on Debian)
* you can start one yourself with dbus-run-session(1) or dbus-launch(1)
* if you are in X11 and something tries to use the session bus without
you already having one, as a last resort, the D-Bus client library
will try to launch a session bus by running dbus-launch(1) in a
The error message you saw that mentioned X11 was because none of the
ways to get a session bus was applicable to your situation, and the last
one that was tried was the last one in that list (which, yes, relies
I suspect that the real problem here is that you are trying to do things
that affect a particular user, from a context where you are not logged in
as that user. This is not something that can generally be supported.
If you explain the problem you are trying to solve, at a higher level,
then perhaps someone can describe how you can solve it. The solution
might involve D-Bus, but it might not.
If you are writing a Debian package's "maintainer scripts" (e.g.
postinst) and you find yourself writing things like
su - user -c "gsettings set something.something something"
then please try to avoid doing that: it is not how GSettings or dconf are
meant to work, and it is not how maintainer scripts are meant to work
either. It is almost always inappropriate for system-level code to
run commands in a per-user context like that.
More information about the dbus