| 1342 | } |
| 1343 | |
| 1344 | void handle_early_opts(struct lightningd *ld, int argc, char *argv[]) |
| 1345 | { |
| 1346 | /* Make ccan/opt use tal for allocations */ |
| 1347 | setup_option_allocators(); |
| 1348 | |
| 1349 | /*~ List features immediately, before doing anything interesting */ |
| 1350 | opt_register_early_noarg("--list-features-only", |
| 1351 | list_features_and_exit, |
| 1352 | ld, opt_hidden); |
| 1353 | |
| 1354 | /*~ This does enough parsing to get us the base configuration options */ |
| 1355 | initial_config_opts(ld, argc, argv, |
| 1356 | &ld->config_filename, |
| 1357 | &ld->config_basedir, |
| 1358 | &ld->config_netdir, |
| 1359 | &ld->rpc_filename); |
| 1360 | |
| 1361 | /* Copy in default config, to be modified by further options */ |
| 1362 | if (chainparams->testnet) |
| 1363 | ld->config = testnet_config; |
| 1364 | else |
| 1365 | ld->config = mainnet_config; |
| 1366 | |
| 1367 | /* Now we can initialize wallet_dsn */ |
| 1368 | ld->wallet_dsn = tal_fmt(ld, "sqlite3://%s/lightningd.sqlite3", |
| 1369 | ld->config_netdir); |
| 1370 | |
| 1371 | /* Set default PID file name to be per-network (in base dir) */ |
| 1372 | ld->pidfile = path_join(ld, ld->config_basedir, |
| 1373 | tal_fmt(tmpctx, "lightningd-%s.pid", |
| 1374 | chainparams->network_name)); |
| 1375 | |
| 1376 | /*~ Move into config dir: this eases path manipulation and also |
| 1377 | * gives plugins a good place to store their stuff. */ |
| 1378 | if (chdir(ld->config_netdir) != 0) { |
| 1379 | log_info(ld->log, "Creating configuration directory %s", |
| 1380 | ld->config_netdir); |
| 1381 | /* We assume home dir exists, so only create two. */ |
| 1382 | if (mkdir(ld->config_basedir, 0700) != 0 && errno != EEXIST) |
| 1383 | fatal("Could not make directory %s: %s", |
| 1384 | ld->config_basedir, |
| 1385 | strerror(errno)); |
| 1386 | if (mkdir(ld->config_netdir, 0700) != 0) |
| 1387 | fatal("Could not make directory %s: %s", |
| 1388 | ld->config_netdir, strerror(errno)); |
| 1389 | if (chdir(ld->config_netdir) != 0) |
| 1390 | fatal("Could not change directory %s: %s", |
| 1391 | ld->config_netdir, strerror(errno)); |
| 1392 | } |
| 1393 | |
| 1394 | /*~ We move files from old locations on first upgrade. */ |
| 1395 | promote_missing_files(ld); |
| 1396 | |
| 1397 | /*~ The ccan/opt code requires registration then parsing; we |
| 1398 | * mimic this API here, even though they're on separate lines.*/ |
| 1399 | register_opts(ld); |
| 1400 | |
| 1401 | /* Now look inside config file(s), but only handle the early |
no test coverage detected