Skip to content

Commit 07dc09f

Browse files
committed
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.
1 parent ebf7349 commit 07dc09f

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

plugins/libplugin.c

+13-8
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ static struct command_result *handle_init(struct command *cmd,
719719
char *dir, *network;
720720
struct json_out *param_obj;
721721
struct plugin *p = cmd->plugin;
722+
bool with_rpc = true;
722723

723724
configtok = json_delve(buf, params, ".configuration");
724725

@@ -742,16 +743,19 @@ static struct command_result *handle_init(struct command *cmd,
742743
addr.sun_path[rpctok->end - rpctok->start] = '\0';
743744
addr.sun_family = AF_UNIX;
744745

745-
if (connect(p->rpc_conn->fd, (struct sockaddr *)&addr, sizeof(addr)) != 0)
746-
plugin_err(p, "Connecting to '%.*s': %s",
746+
if (connect(p->rpc_conn->fd, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
747+
with_rpc = false;
748+
plugin_log(p, LOG_UNUSUAL, "Could not connect to '%.*s': %s",
747749
rpctok->end - rpctok->start, buf + rpctok->start,
748750
strerror(errno));
751+
} else {
752+
param_obj = json_out_obj(NULL, "config", "allow-deprecated-apis");
753+
deprecated_apis = streq(rpc_delve(tmpctx, p, "listconfigs",
754+
take(param_obj),
755+
".allow-deprecated-apis"),
756+
"true");
757+
}
749758

750-
param_obj = json_out_obj(NULL, "config", "allow-deprecated-apis");
751-
deprecated_apis = streq(rpc_delve(tmpctx, p, "listconfigs",
752-
take(param_obj),
753-
".allow-deprecated-apis"),
754-
"true");
755759
opttok = json_get_member(buf, params, "options");
756760
json_for_each_obj(i, t, opttok) {
757761
char *opt = json_strdup(NULL, buf, t);
@@ -772,7 +776,8 @@ static struct command_result *handle_init(struct command *cmd,
772776
if (p->init)
773777
p->init(p, buf, configtok);
774778

775-
io_new_conn(p, p->rpc_conn->fd, rpc_conn_init, p);
779+
if (with_rpc)
780+
io_new_conn(p, p->rpc_conn->fd, rpc_conn_init, p);
776781

777782
return command_success_str(cmd, NULL);
778783
}

0 commit comments

Comments
 (0)