mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-04 14:54:26 +01:00
options: Parse config file before opening working directory
Right now, the `config` file is read *after* the configuration working directory is moved to in the software. However one configuration option `lightning-dir` settable in the `config` file sets this working directory. As the directory is already opened (which defaults to `$HOME/.lightning`) before the configuration is read, the configured directory will not be used. This patch parses the configuration file before opening the working directory, fixing this bug. [ Update CHANGELOG.md and man pages -- RR ]
This commit is contained in:
@@ -613,17 +613,21 @@ static void opt_parse_from_config(struct lightningd *ld)
|
||||
char **all_args; /*For each line: either argument string or NULL*/
|
||||
char *argv[3];
|
||||
int i, argc;
|
||||
char *filename;
|
||||
|
||||
if (ld->config_filename != NULL)
|
||||
filename = ld->config_filename;
|
||||
else
|
||||
filename = path_join(tmpctx, ld->config_dir, "config");
|
||||
|
||||
contents = grab_file(ld, filename);
|
||||
|
||||
if (ld->config_filename != NULL) {
|
||||
contents = grab_file(ld, ld->config_filename);
|
||||
} else
|
||||
contents = grab_file(ld, "config");
|
||||
/* The default config doesn't have to exist, but if the config was
|
||||
* specified on the command line it has to exist. */
|
||||
if (!contents) {
|
||||
if ((errno != ENOENT) || (ld->config_filename != NULL))
|
||||
fatal("Opening and reading config: %s",
|
||||
strerror(errno));
|
||||
fatal("Opening and reading %s: %s",
|
||||
filename, strerror(errno));
|
||||
/* Now we can set up defaults, since no config file. */
|
||||
setup_default_config(ld);
|
||||
return;
|
||||
@@ -805,6 +809,9 @@ void handle_opts(struct lightningd *ld, int argc, char *argv[])
|
||||
/* Get any configdir/testnet options first. */
|
||||
opt_early_parse(argc, argv, opt_log_stderr_exit);
|
||||
|
||||
/* Now look for config file */
|
||||
opt_parse_from_config(ld);
|
||||
|
||||
/* Move to config dir, to save ourselves the hassle of path manip. */
|
||||
if (chdir(ld->config_dir) != 0) {
|
||||
log_unusual(ld->log, "Creating configuration directory %s",
|
||||
@@ -817,9 +824,6 @@ void handle_opts(struct lightningd *ld, int argc, char *argv[])
|
||||
ld->config_dir, strerror(errno));
|
||||
}
|
||||
|
||||
/* Now look for config file */
|
||||
opt_parse_from_config(ld);
|
||||
|
||||
opt_parse(&argc, argv, opt_log_stderr_exit);
|
||||
if (argc != 1)
|
||||
errx(1, "no arguments accepted");
|
||||
|
||||
Reference in New Issue
Block a user