1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
<?xml version='1.0'?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<refentry id="dconf-overview">
<refentryinfo>
<title>dconf Overview</title>
<productname>dconf</productname>
<authorgroup>
<author>
<contrib>Developer</contrib>
<firstname>Ryan</firstname>
<surname>Lortie</surname>
<email>desrt@desrt.ca</email>
</author>
</authorgroup>
</refentryinfo>
<refmeta>
<refentrytitle>dconf</refentrytitle>
<manvolnum>7</manvolnum>
<refmiscinfo class="manual">Conventions and miscellaneous</refmiscinfo>
</refmeta>
<refnamediv>
<refname>dconf</refname>
<refpurpose>A configuration systen</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>
dconf is a simple key/value storage system that is heavily optimised for reading. This makes it an ideal
system for storing user preferences (which are read 1000s of times for each time the user changes one).
It was created with this usecase in mind.
</para>
<para>
All preferences are stored in a single large binary file. Layering of preferences is possible using
multiple files (ie: for site defaults). Lock-down is also supported. The binary file for the defaults
can optionally be compiled from a set of plain text keyfiles.
</para>
<para>
dconf has a partial client/server architecture. It uses D-Bus. The server is only involved in writes
(and is not activated in the user session until the user modifies a preference). The service is stateless
and can exit freely at any time (and is therefore robust against crashes). The list of paths that each
process is watching is stored within the D-Bus daemon itself (as D-Bus signal match rules).
</para>
<para>
Reads are performed by direct access (via mmap) to the on-disk database which is essentially a hashtable.
For this reason, dconf reads typically involve zero system calls and are comparable to a hashtable lookup
in terms of speed. Practically speaking, in simple non-layered setups, dconf is less than 10 times slower
than GHashTable.
</para>
<para>
Writes are assumed only to happen in response to explicit user interaction (like clicking on a checkbox in
a preferences dialog) and are therefore not optimised at all. On some file systems, dconf-service will
call fsync() for every write, which can introduce a latency of up to 100ms. This latency is hidden by the
client libraries through a clever "fast" mechanism that records the outstanding changes locally (so they
can be read back immediately) until the service signals that a write has completed.
</para>
<para>
The binary database format that dconf uses by default is not suitable for use on NFS, where mmap does not
work well. To handle this common use case, dconf can be configured to place its binary database in
<envar>XDG_RUNTIME_DIR</envar> (which is guaranteed to be local, but non-persistent) and synchronize it
with a plain text keyfile in the users home directory.
</para>
</refsect1>
<refsect1>
<title>Profiles</title>
<para>
A profile is a list of configuration databases that dconf consults to find the value for a key. The user's personal
database always takes the highest priority, followed by the system databases in the order prescribed by the profile.
</para>
<para>
On startup, dconf consults the <envar>DCONF_PROFILE</envar> environment variable. If set, dconf will attempt to open
the named profile, aborting if that fails. If the environment variable is not set, it will attempt to open the profile
named "user" and if that fails, it will fall back to an internal hard-wired configuration. dconf stores its profiles
in text files. <envar>DCONF_PROFILE</envar> can specify a relative path to a file in <filename>/etc/dconf/profile/</filename>,
or an absolute path (such as in a user's home directory). The profile name can only use alphanumeric characters or '_'.
</para>
<para>
A profile file might look like the following:
<screen>
user-db:user
system-db:local
system-db:site
</screen>
</para>
<para>
Each line in a profile specifies one dconf database. The first line indicates the database used to write changes, and the
remaining lines indicate read-only databases. (The first line should specify a user-db or service-db, so that users can actually
make configuration changes.)
</para>
<para>
A "user-db" line specifies a user database. These databases are found in <filename><envar>$XDG_CONFIG_HOME</envar>/dconf/</filename>.
The name of the file to open in that directory is exactly as it is written in the profile. This file is expected to be in the binary
dconf database format. Note that <envar>XDG_CONFIG_HOME</envar> cannot be set/modified per terminal or session, because then the writer
and reader would be working on different DBs (the writer is started by DBus and cannot see that variable).
</para>
<para>
A "service-db" line instructs dconf to place the binary database file for the user database in <envar>XDG_RUNTIME_DIR</envar>.
Since this location is not persistent, the rest of the line instructs dconf how to store the database persistently. A typical
line is <literal>service-db:keyfile/user</literal>, which tells dconf to synchronize the binary database with a plain text
keyfile in <filename><envar>$XDG_CONFIG_HOME</envar>/dconf/user.txt</filename>. The synchronization is bi-directional.
</para>
<para>
A "system-db" line specifies a system database. These databases are found in <filename>/etc/dconf/db/</filename>. Again, the name of
the file to open in that directory is exactly as it is written in the profile and the file is expected to be in the dconf database
format.
</para>
<para>
If the <envar>DCONF_PROFILE</envar> environment variable is unset and the "user" profile can not be opened, then the effect is as if
the profile was specified by this file:
<screen>
user-db:user
</screen>
That is, the user's personal database is consulted and there are no system settings.
</para>
</refsect1>
<refsect1>
<title>Key Files</title>
<para>
To facilitate system configuration with a text editor, dconf can populate databases from plain text keyfiles. For any given system
database, keyfiles can be placed into the <filename>/etc/dconf/db/<replaceable>database</replaceable>.d/</filename> directory. The
keyfiles contain groups of settings as follows:
</para>
<screen>
# Some useful default settings for our site
[system/proxy/http]
host='172.16.0.1'
enabled=true
[org/gnome/desktop/background]
picture-uri='file:///usr/local/rupert-corp/company-wallpaper.jpeg'
</screen>
<para>
After changing keyfiles, the database needs to be updated with the
<citerefentry><refentrytitle>dconf</refentrytitle><manvolnum>1</manvolnum></citerefentry> tool.
</para>
</refsect1>
<refsect1>
<title>Locks</title>
<para>
System databases can contain 'locks' for keys. If a lock for a particular key or subpath is installed into a database
then no database listed above that one in the profile will be able to modify any of the affected settings. This can be
used to enforce mandatory settings.
</para>
<para>
To add locks to a database, place text files in the <filename>/etc/dconf/db/<replaceable>database</replaceable>.d/locks</filename>
directory, where <replaceable>database</replaceable> is the name of a system database, as specified in the profile. The files
contain list of keys to lock, on per line. Lines starting with a # are ignored. Here is an example:
</para>
<screen>
# prevent changes to the company wallpaper
/org/gnome/desktop/background/picture-uri
</screen>
<para>
After changing locks, the database needs to be updated with the
<citerefentry><refentrytitle>dconf</refentrytitle><manvolnum>1</manvolnum></citerefentry> tool.
</para>
</refsect1>
<refsect1>
<title>Portability</title>
<para>
dconf mostly targets Free Software operating systems. It will theoretically run on Mac OS but there isn't
much point to that (since Mac OS applications want to store preferences in plist files). It is not
possible to use dconf on Windows because of the inability to rename over a file that's still in use (which
is what the dconf-service does on every write).
</para>
</refsect1>
<refsect1>
<title>API stability</title>
<para>
The dconf API is not particularly friendly, and is not guaranteed to be stable. Because of this and the
lack of portability, you almost certainly want to use some sort of wrapper API around it. The wrapper API
used by GTK+ and GNOME applications is
<ulink url="http://developer.gnome.org/gio/stable/GSettings.html">GSettings</ulink>, which is included as
part of GLib. GSettings has backends for Windows (using the registry) and Mac OS (using property lists) as
well as its dconf backend and is the proper API to use for graphical applications.
</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>dconf-service</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>dconf-editor</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>dconf</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<ulink url="http://developer.gnome.org/gio/stable/GSettings.html">GSettings</ulink>
</para>
</refsect1>
</refentry>
|