20
20
#include " portlist.h"
21
21
#include " perfprocesshandler.h"
22
22
#include < QCoreApplication>
23
+ #include < QDir>
23
24
#include < QTcpServer>
24
25
#include < QProcess>
25
26
#include < errno.h>
@@ -160,21 +161,13 @@ static int findFirstFreePort(Utils::PortList &range)
160
161
return openServer (&s, range);
161
162
}
162
163
163
- static Config parseConfigFile ()
164
+ static bool parseConfigFile (Config *config, const QString &fileName )
164
165
{
165
- Config config;
166
- config.base = config.platform = QLatin1String (" unknown" );
167
- config.debugInterface = Config::LocalDebugInterface;
168
-
169
- #ifdef Q_OS_ANDROID
170
- QFile f (" /system/bin/appcontroller.conf" );
171
- #else
172
- QFile f (" /etc/appcontroller.conf" );
173
- #endif
166
+ QFile f (fileName);
174
167
175
168
if (!f.open (QFile::ReadOnly)) {
176
- fprintf (stderr, " Could not read config file. \n " );
177
- return config ;
169
+ fprintf (stderr, " Could not read config file: %s \n " , qPrintable (fileName) );
170
+ return false ;
178
171
}
179
172
180
173
while (!f.atEnd ()) {
@@ -185,27 +178,44 @@ static Config parseConfigFile()
185
178
if (index < 2 ) {
186
179
// ignore
187
180
} else
188
- config. env [sub.left (index )] = sub.mid (index +1 );
181
+ config-> env [sub.left (index )] = sub.mid (index +1 );
189
182
} else if (line.startsWith (" append=" )) {
190
- config. args += line.mid (7 ).simplified ();
183
+ config-> args += line.mid (7 ).simplified ();
191
184
} else if (line.startsWith (" base=" )) {
192
- config. base = line.mid (5 ).simplified ();
185
+ config-> base = line.mid (5 ).simplified ();
193
186
} else if (line.startsWith (" platform=" )) {
194
- config. platform = line.mid (9 ).simplified ();
187
+ config-> platform = line.mid (9 ).simplified ();
195
188
} else if (line.startsWith (" debugInterface=" )) {
196
189
const QString value = line.mid (15 ).simplified ();
197
190
if (value == " local" )
198
- config. debugInterface = Config::LocalDebugInterface;
191
+ config-> debugInterface = Config::LocalDebugInterface;
199
192
else if (value == " public" )
200
- config. debugInterface = Config::PublicDebugInterface;
193
+ config-> debugInterface = Config::PublicDebugInterface;
201
194
else
202
195
qWarning () << " Unkonwn value for debuginterface:" << value;
203
196
}
204
197
}
205
198
f.close ();
206
- return config ;
199
+ return true ;
207
200
}
208
201
202
+ static bool parseConfigFileDirectory (Config *config, const QString &dirName)
203
+ {
204
+ QDir d (dirName);
205
+ if (d.exists ()) {
206
+ foreach (const QString &fileName, d.entryList (QDir::Files)) {
207
+ const QString file (d.absoluteFilePath (fileName));
208
+
209
+ if (!parseConfigFile (config, file)) {
210
+ fprintf (stderr, " Failed to parse config file: %s\n " , qPrintable (file));
211
+ return false ;
212
+ }
213
+ }
214
+ }
215
+ return true ;
216
+ }
217
+
218
+
209
219
static bool removeDefault ()
210
220
{
211
221
if (QFile::exists (B2QT_PREFIX)) {
@@ -283,7 +293,15 @@ int main(int argc, char **argv)
283
293
return 1 ;
284
294
}
285
295
286
- Config config = parseConfigFile ();
296
+ Config config;
297
+ if (!parseConfigFile (&config, " /etc/appcontroller.conf" )) {
298
+ fprintf (stderr, " Failed to parse config file.\n " );
299
+ return 1 ;
300
+ }
301
+
302
+ // Parse temporary config files
303
+ parseConfigFileDirectory (&config, " /var/lib/b2qt/appcontroller.conf.d" );
304
+ parseConfigFileDirectory (&config, " /tmp/b2qt/appcontroller.conf.d" );
287
305
288
306
while (!args.isEmpty ()) {
289
307
const QString arg (args.takeFirst ());
0 commit comments