From 07dc09f3c717ed5b69ad12deb5b40fb0a770fb11 Mon Sep 17 00:00:00 2001 From: darosior Date: Tue, 7 Jan 2020 18:03:10 +0100 Subject: [PATCH] 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. --- plugins/libplugin.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/libplugin.c b/plugins/libplugin.c index b3baefafc5b6..afa02a670d90 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -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); }