diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index 27d9b192a..28a2b7556 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -92,9 +92,6 @@ bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDE /* Generated stub for fromwire_peektype */ int fromwire_peektype(const u8 *cursor UNNEEDED) { fprintf(stderr, "fromwire_peektype called!\n"); abort(); } -/* Generated stub for fromwire_u8 */ -u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) -{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); } /* Generated stub for fromwire_wireaddr */ bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED) { fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); } diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index 4f2c3ce79..c2841632a 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -56,9 +56,6 @@ bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDE /* Generated stub for fromwire_peektype */ int fromwire_peektype(const u8 *cursor UNNEEDED) { fprintf(stderr, "fromwire_peektype called!\n"); abort(); } -/* Generated stub for fromwire_u8 */ -u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) -{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); } /* Generated stub for fromwire_wireaddr */ bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED) { fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); } diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index c3cc58434..61b4ad807 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -54,9 +54,6 @@ bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDE /* Generated stub for fromwire_peektype */ int fromwire_peektype(const u8 *cursor UNNEEDED) { fprintf(stderr, "fromwire_peektype called!\n"); abort(); } -/* Generated stub for fromwire_u8 */ -u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) -{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); } /* Generated stub for fromwire_wireaddr */ bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED) { fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); } diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 995059f2c..18f357dc6 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -593,13 +593,20 @@ int main(int argc, char *argv[]) * mimic this API here, even though they're on separate lines.*/ register_opts(ld); + /*~ Handle early options, but don't move to --lightning-dir + * just yet. Plugins may add new options, which is why we are + * splitting between early args (including --plugin + * registration) and non-early opts. */ + handle_early_opts(ld, argc, argv); + + /*~ Initialize all the plugins we just registered, so they can + * do their thing and tell us about themselves (including + * options registration). */ + plugins_init(ld->plugins); + /*~ Handle options and config; move to .lightningd (--lightning-dir) */ handle_opts(ld, argc, argv); - /*~ Initialize all the plugins we just registered, so they can do their - * thing and tell us about themselves */ - plugins_init(ld->plugins); - /*~ Make sure we can reach the subdaemons, and versions match. */ test_subdaemons(ld); diff --git a/lightningd/options.c b/lightningd/options.c index d7962059a..b5391be5f 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -619,8 +619,11 @@ static void config_log_stderr_exit(const char *fmt, ...) fatal("%s", msg); } -/* We turn the config file into cmdline arguments. */ -static void opt_parse_from_config(struct lightningd *ld) +/** + * We turn the config file into cmdline arguments. @early tells us + * whether to parse early options only, or the non-early options. + */ +static void opt_parse_from_config(struct lightningd *ld, bool early) { char *contents, **lines; char **all_args; /*For each line: either argument string or NULL*/ @@ -669,23 +672,28 @@ static void opt_parse_from_config(struct lightningd *ld) argv[0] = "lightning config file"; argv[argc] = NULL; - for (i = 0; i < tal_count(all_args); i++) { - if(all_args[i] != NULL) { - config_parse_line_number = i + 1; - argv[1] = all_args[i]; - opt_early_parse(argc, argv, config_log_stderr_exit); + if (early) { + for (i = 0; i < tal_count(all_args); i++) { + if (all_args[i] != NULL) { + config_parse_line_number = i + 1; + argv[1] = all_args[i]; + opt_early_parse(argc, argv, + config_log_stderr_exit); + } } - } - /* Now we can set up defaults, depending on whether testnet or not */ - setup_default_config(ld); + /* Now we can set up defaults, depending on whether testnet or + * not */ + setup_default_config(ld); + } else { - for (i = 0; i < tal_count(all_args); i++) { - if(all_args[i] != NULL) { - config_parse_line_number = i + 1; - argv[1] = all_args[i]; - opt_parse(&argc, argv, config_log_stderr_exit); - argc = 2; /* opt_parse might have changed it */ + for (i = 0; i < tal_count(all_args); i++) { + if (all_args[i] != NULL) { + config_parse_line_number = i + 1; + argv[1] = all_args[i]; + opt_parse(&argc, argv, config_log_stderr_exit); + argc = 2; /* opt_parse might have changed it */ + } } } @@ -813,18 +821,22 @@ void setup_color_and_alias(struct lightningd *ld) } } -void handle_opts(struct lightningd *ld, int argc, char *argv[]) +void handle_early_opts(struct lightningd *ld, int argc, char *argv[]) { /* Load defaults. The actual values loaded here will be overwritten * later by opt_parse_from_config. */ setup_default_config(ld); /* Get any configdir/testnet options first. */ - opt_early_parse(argc, argv, opt_log_stderr_exit); + opt_early_parse_incomplete(argc, argv, opt_log_stderr_exit); - /* Now look for config file */ - opt_parse_from_config(ld); + /* Now look for config file, but only handle the early + * options, others may be added on-demand */ + opt_parse_from_config(ld, true); +} +void handle_opts(struct lightningd *ld, int argc, char *argv[]) +{ /* 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", @@ -837,6 +849,11 @@ void handle_opts(struct lightningd *ld, int argc, char *argv[]) ld->config_dir, strerror(errno)); } + /* Now look for config file, but only handle non-early + * options, early ones have been parsed in + * handle_early_opts */ + opt_parse_from_config(ld, false); + opt_parse(&argc, argv, opt_log_stderr_exit); if (argc != 1) errx(1, "no arguments accepted"); diff --git a/lightningd/options.h b/lightningd/options.h index 9208a1f59..eff1c0bba 100644 --- a/lightningd/options.h +++ b/lightningd/options.h @@ -9,6 +9,9 @@ struct lightningd; void register_opts(struct lightningd *ld); /* After this, we're in the .lightning dir, config files parsed. */ +void handle_early_opts(struct lightningd *ld, int argc, char *argv[]); + +/* After this we've parsed all options */ void handle_opts(struct lightningd *ld, int argc, char *argv[]); /* Derive default color and alias from the pubkey. */ diff --git a/lightningd/test/run-find_my_abspath.c b/lightningd/test/run-find_my_abspath.c index e14dd9a3a..5169c06e4 100644 --- a/lightningd/test/run-find_my_abspath.c +++ b/lightningd/test/run-find_my_abspath.c @@ -72,6 +72,9 @@ struct log_book *get_log_book(const struct log *log UNNEEDED) /* Generated stub for gossip_init */ void gossip_init(struct lightningd *ld UNNEEDED, int connectd_fd UNNEEDED) { fprintf(stderr, "gossip_init called!\n"); abort(); } +/* Generated stub for handle_early_opts */ +void handle_early_opts(struct lightningd *ld UNNEEDED, int argc UNNEEDED, char *argv[]) +{ fprintf(stderr, "handle_early_opts called!\n"); abort(); } /* Generated stub for handle_opts */ void handle_opts(struct lightningd *ld UNNEEDED, int argc UNNEEDED, char *argv[]) { fprintf(stderr, "handle_opts called!\n"); abort(); }