mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
plugins/libplugin: don't crash if 'lightning-rpc' doesnt exist (yet)
We are going to initialize a plugin before its creation, so log as UNUSUAL instead. Also, `pay` and `fundchannel` inits are using rpc_delve(), so we need to io_new_conn() (which sets the socket as non blocking) after calling the plugin's init.
This commit is contained in:
parent
c1009635ed
commit
5840e90ceb
1 changed files with 13 additions and 8 deletions
|
@ -719,6 +719,7 @@ static struct command_result *handle_init(struct command *cmd,
|
|||
char *dir, *network;
|
||||
struct json_out *param_obj;
|
||||
struct plugin *p = cmd->plugin;
|
||||
bool with_rpc = true;
|
||||
|
||||
configtok = json_delve(buf, params, ".configuration");
|
||||
|
||||
|
@ -742,16 +743,19 @@ static struct command_result *handle_init(struct command *cmd,
|
|||
addr.sun_path[rpctok->end - rpctok->start] = '\0';
|
||||
addr.sun_family = AF_UNIX;
|
||||
|
||||
if (connect(p->rpc_conn->fd, (struct sockaddr *)&addr, sizeof(addr)) != 0)
|
||||
plugin_err(p, "Connecting to '%.*s': %s",
|
||||
if (connect(p->rpc_conn->fd, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
|
||||
with_rpc = false;
|
||||
plugin_log(p, LOG_UNUSUAL, "Could not connect to '%.*s': %s",
|
||||
rpctok->end - rpctok->start, buf + rpctok->start,
|
||||
strerror(errno));
|
||||
} else {
|
||||
param_obj = json_out_obj(NULL, "config", "allow-deprecated-apis");
|
||||
deprecated_apis = streq(rpc_delve(tmpctx, p, "listconfigs",
|
||||
take(param_obj),
|
||||
".allow-deprecated-apis"),
|
||||
"true");
|
||||
}
|
||||
|
||||
param_obj = json_out_obj(NULL, "config", "allow-deprecated-apis");
|
||||
deprecated_apis = streq(rpc_delve(tmpctx, p, "listconfigs",
|
||||
take(param_obj),
|
||||
".allow-deprecated-apis"),
|
||||
"true");
|
||||
opttok = json_get_member(buf, params, "options");
|
||||
json_for_each_obj(i, t, opttok) {
|
||||
char *opt = json_strdup(NULL, buf, t);
|
||||
|
@ -772,7 +776,8 @@ static struct command_result *handle_init(struct command *cmd,
|
|||
if (p->init)
|
||||
p->init(p, buf, configtok);
|
||||
|
||||
io_new_conn(p, p->rpc_conn->fd, rpc_conn_init, p);
|
||||
if (with_rpc)
|
||||
io_new_conn(p, p->rpc_conn->fd, rpc_conn_init, p);
|
||||
|
||||
return command_success_str(cmd, NULL);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue