diff --git a/cli/lightning-cli.c b/cli/lightning-cli.c index 99fd8ed0a..647fefc7d 100644 --- a/cli/lightning-cli.c +++ b/cli/lightning-cli.c @@ -392,12 +392,13 @@ int main(int argc, char *argv[]) int fd, i; size_t off; const char *method; - char *cmd, *resp, *idstr, *rpc_filename; + char *cmd, *resp, *idstr; struct sockaddr_un addr; jsmntok_t *toks; const jsmntok_t *result, *error, *id; - char *lightning_dir; const tal_t *ctx = tal(NULL, char); + char *lightning_dir = default_configdir(ctx); + char *rpc_filename = default_rpcfile(ctx); jsmn_parser parser; int parserr; enum format format = DEFAULT_FORMAT; @@ -409,7 +410,14 @@ int main(int argc, char *argv[]) jsmn_init(&parser); opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn); - configdir_register_opts(ctx, &lightning_dir, &rpc_filename); + + opt_register_arg("--lightning-dir=", opt_set_talstr, opt_show_charp, + &lightning_dir, + "Set working directory. All other files are relative to this"); + + opt_register_arg("--rpc-file", opt_set_talstr, opt_show_charp, + &rpc_filename, + "Set JSON-RPC socket (or /dev/tty)"); opt_register_noarg("--help|-h", opt_usage_and_exit, " [...]", "Show this message. Use the command help (without hyphens -- \"lightning-cli help\") to get a list of all RPC commands"); diff --git a/common/configdir.c b/common/configdir.c index b8584d8a3..3088169c2 100644 --- a/common/configdir.c +++ b/common/configdir.c @@ -11,7 +11,7 @@ char *opt_set_talstr(const char *arg, char **p) return opt_set_charp(tal_strdup(NULL, arg), p); } -static char *default_configdir(const tal_t *ctx) +char *default_configdir(const tal_t *ctx) { char *path; const char *env = getenv("HOME"); @@ -22,17 +22,7 @@ static char *default_configdir(const tal_t *ctx) return path; } -void configdir_register_opts(const tal_t *ctx, - char **configdir, char **rpc_filename) +char *default_rpcfile(const tal_t *ctx) { - *configdir = default_configdir(ctx); - *rpc_filename = tal_strdup(ctx, "lightning-rpc"); - - opt_register_early_arg("--lightning-dir=", opt_set_talstr, opt_show_charp, - configdir, - "Set working directory. All other files are relative to this"); - - opt_register_arg("--rpc-file", opt_set_talstr, opt_show_charp, - rpc_filename, - "Set JSON-RPC socket (or /dev/tty)"); + return tal_strdup(ctx, "lightning-rpc"); } diff --git a/common/configdir.h b/common/configdir.h index 5c7971ebb..9bd3f8d51 100644 --- a/common/configdir.h +++ b/common/configdir.h @@ -6,7 +6,10 @@ /* Helper for options which are tal() strings. */ char *opt_set_talstr(const char *arg, char **p); -void configdir_register_opts(const tal_t *ctx, - char **config_dir, char **rpc_filename); +/* The default configuration dir: ~/.lightning */ +char *default_configdir(const tal_t *ctx); + +/* The default rpc filename: lightning-rpc */ +char *default_rpcfile(const tal_t *ctx); #endif /* LIGHTNING_COMMON_CONFIGDIR_H */ diff --git a/lightningd/options.c b/lightningd/options.c index 8ac418b2e..920605d72 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -836,6 +836,10 @@ void register_opts(struct lightningd *ld) { opt_set_alloc(opt_allocfn, tal_reallocfn, tal_freefn); + ld->rpc_filename = default_rpcfile(ld); + opt_register_arg("--rpc-file", opt_set_talstr, opt_show_charp, + &ld->rpc_filename, + "Set JSON-RPC socket (or /dev/tty)"); opt_register_noarg("--help|-h", opt_lightningd_usage, ld, "Print this message."); opt_register_early_noarg("--test-daemons-only", @@ -878,7 +882,6 @@ void register_opts(struct lightningd *ld) opt_register_logging(ld); opt_register_version(); - configdir_register_opts(ld, &ld->config_dir, &ld->rpc_filename); config_register_opts(ld); #if DEVELOPER dev_register_opts(ld); @@ -942,6 +945,11 @@ void handle_early_opts(struct lightningd *ld, int argc, char *argv[]) * later by opt_parse_from_config. */ setup_default_config(ld); + ld->config_dir = default_configdir(ld); + opt_register_early_arg("--lightning-dir=", opt_set_talstr, opt_show_charp, + &ld->config_dir, + "Set working directory. All other files are relative to this"); + /* Get any configdir/testnet options first. */ opt_early_parse_incomplete(argc, argv, opt_log_stderr_exit);