MCPcopy Create free account
hub / github.com/ElementsProject/lightning / handle_early_opts

Function handle_early_opts

lightningd/options.c:1344–1410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1342}
1343
1344void 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

Callers 1

mainFunction · 0.70

Calls 10

setup_option_allocatorsFunction · 0.85
initial_config_optsFunction · 0.85
path_joinFunction · 0.85
log_infoClass · 0.85
promote_missing_filesFunction · 0.85
register_optsFunction · 0.85
parse_config_filesFunction · 0.85
logging_options_parsedFunction · 0.85
fatalFunction · 0.70

Tested by

no test coverage detected