Skip to content

Commit 4914b28

Browse files
committed
netatalk: replace gsettings with dconf keyfile for indexer config
The gsettings set approach was broken at runtime because gsettings requires a dconf-service on the session bus, which netatalk's private dbus-daemon does not auto-activate. Replace set_sl_volumes() with a dconf keyfile writer: it creates /etc/dconf/db/netatalk.d/10-spotlight and runs dconf update, which works without any session bus. Add DCONF_PROFILE env so the indexer reads from the netatalk-specific database. Ship config/dconf/netatalk (system-db:netatalk) as the dconf profile, installed to sysconfdir/dconf/profile/. Detect the dconf binary at build time and gate have_spotlight on it instead of gsettings.
1 parent 6dada79 commit 4914b28

6 files changed

Lines changed: 73 additions & 50 deletions

File tree

config/dconf/meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
install_data(
2+
'netatalk',
3+
install_dir: sysconfdir / 'dconf/profile',
4+
install_tag: 'config',
5+
)

config/dconf/netatalk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
system-db:netatalk

config/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ else
1111
endif
1212

1313
if have_spotlight
14+
subdir('dconf')
15+
1416
dbus_session_conf = configure_file(
1517
input: 'dbus-session.conf.in',
1618
output: 'dbus-session.conf',

etc/netatalk/netatalk.c

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <stdlib.h>
2323
#include <string.h>
2424
#include <sys/param.h>
25+
#include <sys/stat.h>
2526
#include <sys/resource.h>
2627
#include <sys/socket.h>
2728
#include <sys/time.h>
@@ -99,82 +100,68 @@ static bool service_running(pid_t pid)
99100
}
100101

101102
#ifdef WITH_SPOTLIGHT
102-
/*! Set indexers to index all our volumes */
103+
/*! Set indexers to index all our volumes via a dconf keyfile */
103104
static int set_sl_volumes(void)
104105
{
105106
EC_INIT;
106107
const struct vol *volumes, *vol;
107-
struct bstrList *vollist = bstrListCreate();
108+
FILE *fp = NULL;
108109
int sysret;
109-
bstring sep = bfromcstr(", ");
110-
bstring volnamelist = NULL, cmd = NULL;
110+
bool first;
111+
111112
EC_NULL_LOG(volumes = getvolumes());
112113

114+
if (mkdir(INDEXER_DCONF_DB_DIR, 0755) != 0 && errno != EEXIST) {
115+
LOG(log_error, logtype_sl,
116+
"set_sl_volumes: failed to create " INDEXER_DCONF_DB_DIR ": %s",
117+
strerror(errno));
118+
EC_FAIL;
119+
}
120+
121+
if ((fp = fopen(INDEXER_DCONF_DB_DIR "/10-spotlight", "w")) == NULL) {
122+
LOG(log_error, logtype_sl,
123+
"set_sl_volumes: failed to open " INDEXER_DCONF_DB_DIR "/10-spotlight: %s",
124+
strerror(errno));
125+
EC_FAIL;
126+
}
127+
128+
fprintf(fp, "[" INDEXER_DCONF_PATH "]\n");
129+
fprintf(fp, "index-recursive-directories=[");
130+
first = true;
131+
113132
for (vol = volumes; vol; vol = vol->v_next) {
114133
if (vol->v_flags & AFPVOL_SPOTLIGHT) {
115-
bstring volnamequot = bformat("'%s'", vol->v_path);
116-
117-
if (vollist->qty == vollist->mlen
118-
&& bstrListAlloc(vollist, vollist->qty + 1) != BSTR_OK) {
119-
LOG(log_error, logtype_default,
120-
"set_sl_volumes: failed to initialize indexing for %s",
121-
bdata(volnamequot));
134+
if (!first) {
135+
fprintf(fp, ", ");
122136
}
123-
124-
vollist->entry[vollist->qty] = volnamequot;
125-
vollist->qty++;
137+
fprintf(fp, "'%s'", vol->v_path);
138+
first = false;
126139
}
127140
}
128141

129-
volnamelist = bjoin(vollist, sep);
130-
cmd = bformat("gsettings set " INDEXER_GSETTINGS_SCHEMA
131-
" index-recursive-directories \"[%s]\"",
132-
bdata(volnamelist) ? bdata(volnamelist) : "");
133-
LOG(log_debug, logtype_sl, "set_sl_volumes: %s", bdata(cmd));
134-
sysret = system(bdata(cmd));
135-
136-
if (sysret == -1) {
137-
LOG(log_error, logtype_sl, "set_sl_volumes: system() failed to run '%s': %s",
138-
bdata(cmd), strerror(errno));
139-
EC_FAIL;
140-
} else if (sysret != 0) {
141-
LOG(log_error, logtype_sl, "set_sl_volumes: command '%s' exited with status %d",
142-
bdata(cmd), WEXITSTATUS(sysret));
143-
EC_FAIL;
144-
}
142+
fprintf(fp, "]\n");
143+
fprintf(fp, "index-single-directories=@as []\n");
144+
fclose(fp);
145+
fp = NULL;
145146

146-
/* Disable default root user home indexing */
147-
sysret = system("gsettings set " INDEXER_GSETTINGS_SCHEMA
148-
" index-single-directories \"[]\"");
147+
sysret = system("dconf update");
149148

150149
if (sysret == -1) {
151150
LOG(log_error, logtype_sl,
152-
"set_sl_volumes: system() failed to run disable home indexing: %s",
151+
"set_sl_volumes: system() failed to run 'dconf update': %s",
153152
strerror(errno));
154153
EC_FAIL;
155154
} else if (sysret != 0) {
156155
LOG(log_error, logtype_sl,
157-
"set_sl_volumes: disable home indexing exited with status %d",
156+
"set_sl_volumes: 'dconf update' exited with status %d",
158157
WEXITSTATUS(sysret));
159158
EC_FAIL;
160159
}
161160

162161
EC_CLEANUP:
163162

164-
if (cmd) {
165-
bdestroy(cmd);
166-
}
167-
168-
if (sep) {
169-
bdestroy(sep);
170-
}
171-
172-
if (vollist) {
173-
bstrListDestroy(vollist);
174-
}
175-
176-
if (volnamelist) {
177-
bdestroy(volnamelist);
163+
if (fp) {
164+
fclose(fp);
178165
}
179166

180167
EC_EXIT;
@@ -712,6 +699,7 @@ int main(int argc, char **argv)
712699
if (obj.options.flags & OPTION_SPOTLIGHT) {
713700
setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path=" _PATH_STATEDIR "spotlight.ipc",
714701
1);
702+
setenv("DCONF_PROFILE", INDEXER_DCONF_PROFILE, 1);
715703
setenv("XDG_DATA_HOME", _PATH_STATEDIR, 0);
716704
setenv("XDG_CACHE_HOME", _PATH_STATEDIR, 0);
717705
setenv("TRACKER_USE_LOG_FILES", "1", 0);

meson.build

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ if get_option('with-spotlight')
11251125
localsearch = find_program('localsearch', required: false)
11261126
tracker3 = find_program('tracker3', required: false)
11271127
gsettings = find_program('gsettings', required: false)
1128+
dconf = find_program('dconf', required: false)
11281129

11291130
localsearch3_schema_found = false
11301131
tracker3_schema_found = false
@@ -1159,6 +1160,10 @@ if get_option('with-spotlight')
11591160
'INDEXER_GSETTINGS_SCHEMA',
11601161
'"org.freedesktop.LocalSearch3.Miner.Files"',
11611162
)
1163+
cdata.set(
1164+
'INDEXER_DCONF_PATH',
1165+
'"org/freedesktop/localsearch3/miner/files"',
1166+
)
11621167
cdata.set('INDEXER_COMMAND', '"' + indexer.full_path() + ' daemon"')
11631168
elif indexer.found() and tracker3_schema_found
11641169
indexer_found = true
@@ -1167,13 +1172,26 @@ if get_option('with-spotlight')
11671172
'INDEXER_GSETTINGS_SCHEMA',
11681173
'"org.freedesktop.Tracker3.Miner.Files"',
11691174
)
1175+
cdata.set(
1176+
'INDEXER_DCONF_PATH',
1177+
'"org/freedesktop/tracker3/miner/files"',
1178+
)
11701179
cdata.set('INDEXER_COMMAND', '"' + indexer.full_path() + ' daemon"')
11711180
endif
11721181

1182+
cdata.set(
1183+
'INDEXER_DCONF_DB_DIR',
1184+
'"' + sysconfdir / 'dconf/db/netatalk.d' + '"',
1185+
)
1186+
cdata.set(
1187+
'INDEXER_DCONF_PROFILE',
1188+
'"' + sysconfdir / 'dconf/profile/netatalk' + '"',
1189+
)
1190+
11731191
have_spotlight = (
11741192
sparql_found
11751193
and indexer_found
1176-
and gsettings.found()
1194+
and dconf.found()
11771195
and talloc.found()
11781196
and flex.found()
11791197
and bison.found()

meson_config.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,15 @@
406406
/* Indexer GSettings schema (may differ from D-Bus name) */
407407
#mesondefine INDEXER_GSETTINGS_SCHEMA
408408

409+
/* Indexer dconf keyfile path (schema with dots replaced by slashes, lowercased) */
410+
#mesondefine INDEXER_DCONF_PATH
411+
412+
/* Directory for the netatalk dconf database keyfiles */
413+
#mesondefine INDEXER_DCONF_DB_DIR
414+
415+
/* Path to the netatalk dconf profile file */
416+
#mesondefine INDEXER_DCONF_PROFILE
417+
409418
/* Define if cracklib should be used */
410419
#mesondefine USE_CRACKLIB
411420

0 commit comments

Comments
 (0)