Skip to content

Commit

Permalink
common: return location of a ".setconfig" file when we load config.
Browse files Browse the repository at this point in the history
This is where we will put all the dynamic settings.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Feb 24, 2025
1 parent da2fb19 commit f4872f9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
25 changes: 20 additions & 5 deletions common/configdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static struct configvar **gather_file_configvars(const tal_t *ctx,
enum configvar_src src,
const char *filename,
bool must_exist,
char **setconfig_file,
size_t include_depth)
{
char *contents, **lines;
Expand All @@ -72,6 +73,13 @@ static struct configvar **gather_file_configvars(const tal_t *ctx,
return cvs;
}

/* First .setconfig file is used for setconfig command */
if (setconfig_file
&& *setconfig_file == NULL
&& strends(filename, ".setconfig")) {
*setconfig_file = tal_strdup(ctx, filename);
}

/* Break into lines. */
lines = tal_strsplit(contents, contents, "\r\n", STR_EMPTY_OK);
for (size_t i = 0; i < tal_count(lines) - 1; i++) {
Expand All @@ -93,6 +101,7 @@ static struct configvar **gather_file_configvars(const tal_t *ctx,
take(path_dirname(NULL, filename)),
included),
true,
setconfig_file,
include_depth + 1);
cvs = configvar_join(ctx, take(cvs), take(sub));
continue;
Expand Down Expand Up @@ -291,7 +300,7 @@ void minimal_config_opts(const tal_t *ctx,
config_filename,
basedir,
config_netdir,
rpc_filename);
rpc_filename, NULL);
tal_steal(ctx, *config_filename);
tal_steal(ctx, *basedir);
tal_steal(ctx, *config_netdir);
Expand All @@ -304,7 +313,8 @@ struct configvar **initial_config_opts(const tal_t *ctx,
char **config_filename,
char **config_basedir,
char **config_netdir,
char **rpc_filename)
char **rpc_filename,
char **setconfig_file)
{
struct configvar **cmdline_cvs, **config_cvs, **cvs;

Expand Down Expand Up @@ -360,19 +370,24 @@ struct configvar **initial_config_opts(const tal_t *ctx,
cmdline_cvs = gather_cmdline_args(tmpctx, argc, argv, remove_args);
parse_configvars(cmdline_cvs, true, false, false);

if (setconfig_file)
*setconfig_file = NULL;

/* Base default or direct config can set network */
if (*config_filename) {
config_cvs = gather_file_configvars(NULL,
CONFIGVAR_EXPLICIT_CONF,
*config_filename, true, 0);
*config_filename, true,
setconfig_file, 0);
} else {
struct configvar **base_cvs, **net_cvs;
char *dir = path_join(tmpctx, take(path_cwd(NULL)), *config_basedir);
/* Optional: .lightning/config */
base_cvs = gather_file_configvars(tmpctx,
CONFIGVAR_BASE_CONF,
path_join(tmpctx, dir, "config"),
false, 0);
false,
setconfig_file, 0);
/* This might set network! */
parse_configvars(configvar_join(tmpctx, base_cvs, cmdline_cvs),
true, false, false);
Expand All @@ -382,7 +397,7 @@ struct configvar **initial_config_opts(const tal_t *ctx,
net_cvs = gather_file_configvars(tmpctx,
CONFIGVAR_NETWORK_CONF,
path_join(tmpctx, dir, "config"),
false, 0);
false, setconfig_file, 0);
config_cvs = configvar_join(NULL, take(base_cvs), take(net_cvs));
}
cvs = configvar_join(ctx, take(config_cvs), cmdline_cvs);
Expand Down
3 changes: 2 additions & 1 deletion common/configdir.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ struct configvar **initial_config_opts(const tal_t *ctx,
char **config_filename,
char **config_basedir,
char **config_netdir,
char **rpc_filename);
char **rpc_filename,
char **setconfig_file);

/* This is called before we know all the options. */
void parse_configvars_early(struct configvar **cvs, bool developer);
Expand Down
3 changes: 3 additions & 0 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ struct lightningd {
/* Our config basedir, network directory, and rpc file */
char *config_basedir, *config_netdir;

/* Where setconfig() should write to (or NULL if not set up yet) */
char *setconfig_file;

/* Location of the RPC socket. */
char *rpc_filename;
/* Mode of the RPC filename. */
Expand Down
3 changes: 2 additions & 1 deletion lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,8 @@ void handle_early_opts(struct lightningd *ld, int argc, char *argv[])
&ld->config_filename,
&ld->config_basedir,
&ld->config_netdir,
&ld->rpc_filename);
&ld->rpc_filename,
&ld->setconfig_file);

if (argc != 1)
errx(1, "no arguments accepted");
Expand Down

0 comments on commit f4872f9

Please sign in to comment.