mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +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;
|
jsmntok_t *toks;
|
||||||
const jsmntok_t *result, *error, *id;
|
const jsmntok_t *result, *error, *id;
|
||||||
const tal_t *ctx = tal(NULL, char);
|
const tal_t *ctx = tal(NULL, char);
|
||||||
char *net_dir, *rpc_filename;
|
char *config_filename, *base_dir, *net_dir, *rpc_filename;
|
||||||
jsmn_parser parser;
|
jsmn_parser parser;
|
||||||
int parserr;
|
int parserr;
|
||||||
enum format format = DEFAULT_FORMAT;
|
enum format format = DEFAULT_FORMAT;
|
||||||
|
@ -668,7 +668,8 @@ int main(int argc, char *argv[])
|
||||||
setup_option_allocators();
|
setup_option_allocators();
|
||||||
|
|
||||||
opt_exitcode = ERROR_USAGE;
|
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,
|
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");
|
"<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,
|
void minimal_config_opts(const tal_t *ctx,
|
||||||
int argc, char *argv[],
|
int argc, char *argv[],
|
||||||
|
char **config_filename,
|
||||||
|
char **basedir,
|
||||||
char **config_netdir,
|
char **config_netdir,
|
||||||
char **rpc_filename)
|
char **rpc_filename)
|
||||||
{
|
{
|
||||||
char *unused_filename, *unused_basedir;
|
|
||||||
|
|
||||||
initial_config_opts(tmpctx, &argc, argv, false,
|
initial_config_opts(tmpctx, &argc, argv, false,
|
||||||
&unused_filename,
|
config_filename,
|
||||||
&unused_basedir,
|
basedir,
|
||||||
config_netdir,
|
config_netdir,
|
||||||
rpc_filename);
|
rpc_filename);
|
||||||
|
tal_steal(ctx, *config_filename);
|
||||||
|
tal_steal(ctx, *basedir);
|
||||||
tal_steal(ctx, *config_netdir);
|
tal_steal(ctx, *config_netdir);
|
||||||
tal_steal(ctx, *rpc_filename);
|
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 */
|
/* Minimal config parsing for tools: use opt_early_parse/opt_parse after */
|
||||||
void minimal_config_opts(const tal_t *ctx,
|
void minimal_config_opts(const tal_t *ctx,
|
||||||
int argc, char *argv[],
|
int argc, char *argv[],
|
||||||
|
char **config_filename,
|
||||||
|
char **basedir,
|
||||||
char **config_netdir,
|
char **config_netdir,
|
||||||
char **rpc_filename);
|
char **rpc_filename);
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,7 @@ static void copy_column(void *dst, size_t size,
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
char *config_filename, *base_dir;
|
||||||
char *net_dir, *rpc_filename, *hsmfile, *dbfile;
|
char *net_dir, *rpc_filename, *hsmfile, *dbfile;
|
||||||
sqlite3 *sql;
|
sqlite3 *sql;
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
|
@ -124,7 +125,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
setup_option_allocators();
|
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,
|
opt_register_noarg("-v|--verbose", opt_set_bool, &verbose,
|
||||||
"Print everything");
|
"Print everything");
|
||||||
|
|
Loading…
Add table
Reference in a new issue