mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-20 13:54:36 +01:00
cli: don't crash when there's no argument
This should provide the default help message and exit, but was resulting in a segmentation fault from freeing pointers passed to the default config. Changelog-Fixed: lightning-cli properly returns help without argument
This commit is contained in:
parent
5531c9d460
commit
bd4a001279
4 changed files with 14 additions and 7 deletions
|
@ -650,7 +650,7 @@ int main(int argc, char *argv[])
|
|||
jsmntok_t *toks;
|
||||
const jsmntok_t *result, *error, *id;
|
||||
const tal_t *ctx = tal(NULL, char);
|
||||
char *net_dir, *rpc_filename;
|
||||
char *config_filename, *base_dir, *net_dir, *rpc_filename;
|
||||
jsmn_parser parser;
|
||||
int parserr;
|
||||
enum format format = DEFAULT_FORMAT;
|
||||
|
@ -668,7 +668,8 @@ int main(int argc, char *argv[])
|
|||
setup_option_allocators();
|
||||
|
||||
opt_exitcode = ERROR_USAGE;
|
||||
minimal_config_opts(ctx, argc, argv, &net_dir, &rpc_filename);
|
||||
minimal_config_opts(ctx, argc, argv, &config_filename, &base_dir,
|
||||
&net_dir, &rpc_filename);
|
||||
|
||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||
"<command> [<params>...]", "Show this message. Use the command help (without hyphens -- \"lightning-cli help\") to get a list of all RPC commands");
|
||||
|
|
|
@ -281,16 +281,18 @@ static struct configvar **gather_cmdline_args(const tal_t *ctx,
|
|||
|
||||
void minimal_config_opts(const tal_t *ctx,
|
||||
int argc, char *argv[],
|
||||
char **config_filename,
|
||||
char **basedir,
|
||||
char **config_netdir,
|
||||
char **rpc_filename)
|
||||
{
|
||||
char *unused_filename, *unused_basedir;
|
||||
|
||||
initial_config_opts(tmpctx, &argc, argv, false,
|
||||
&unused_filename,
|
||||
&unused_basedir,
|
||||
config_filename,
|
||||
basedir,
|
||||
config_netdir,
|
||||
rpc_filename);
|
||||
tal_steal(ctx, *config_filename);
|
||||
tal_steal(ctx, *basedir);
|
||||
tal_steal(ctx, *config_netdir);
|
||||
tal_steal(ctx, *rpc_filename);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ void setup_option_allocators(void);
|
|||
/* Minimal config parsing for tools: use opt_early_parse/opt_parse after */
|
||||
void minimal_config_opts(const tal_t *ctx,
|
||||
int argc, char *argv[],
|
||||
char **config_filename,
|
||||
char **basedir,
|
||||
char **config_netdir,
|
||||
char **rpc_filename);
|
||||
|
||||
|
|
|
@ -109,6 +109,7 @@ static void copy_column(void *dst, size_t size,
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *config_filename, *base_dir;
|
||||
char *net_dir, *rpc_filename, *hsmfile, *dbfile;
|
||||
sqlite3 *sql;
|
||||
sqlite3_stmt *stmt;
|
||||
|
@ -124,7 +125,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
setup_option_allocators();
|
||||
|
||||
minimal_config_opts(top_ctx, argc, argv, &net_dir, &rpc_filename);
|
||||
minimal_config_opts(top_ctx, argc, argv, &config_filename, &base_dir,
|
||||
&net_dir, &rpc_filename);
|
||||
|
||||
opt_register_noarg("-v|--verbose", opt_set_bool, &verbose,
|
||||
"Print everything");
|
||||
|
|
Loading…
Add table
Reference in a new issue