From 7223a9446e61d711b880eba5dcb8dd463df7a566 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 5 May 2020 10:44:32 +0930 Subject: [PATCH] lightningd: have plugin_send_getmanifest return an error string. This way the caller doesn't have to "know" that it should use strerror(). Signed-off-by: Rusty Russell --- lightningd/plugin.c | 11 +++++++---- lightningd/plugin.h | 4 +++- lightningd/plugin_control.c | 8 +++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index f55fb2e76..f89e278d7 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -1224,7 +1224,7 @@ void plugins_add_default_dir(struct plugins *plugins) } } -bool plugin_send_getmanifest(struct plugin *p) +const char *plugin_send_getmanifest(struct plugin *p) { char **cmd; int stdin, stdout; @@ -1242,7 +1242,7 @@ bool plugin_send_getmanifest(struct plugin *p) cmd[1] = "--debugger"; p->pid = pipecmdarr(&stdin, &stdout, &pipecmd_preserve, cmd); if (p->pid == -1) - return false; + return tal_fmt(p, "opening pipe: %s", strerror(errno)); log_debug(p->plugins->log, "started(%u) %s", p->pid, p->cmd); p->buffer = tal_arr(p, char, 64); @@ -1268,7 +1268,7 @@ bool plugin_send_getmanifest(struct plugin *p) plugin_manifest_timeout, p); } - return true; + return NULL; } bool plugins_send_getmanifest(struct plugins *plugins) @@ -1278,9 +1278,12 @@ bool plugins_send_getmanifest(struct plugins *plugins) /* Spawn the plugin processes before entering the io_loop */ list_for_each_safe(&plugins->plugins, p, next, list) { + const char *err; + if (p->plugin_state != UNCONFIGURED) continue; - if (plugin_send_getmanifest(p)) { + err = plugin_send_getmanifest(p); + if (!err) { sent = true; continue; } diff --git a/lightningd/plugin.h b/lightningd/plugin.h index f1db616cb..1877fd821 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -196,8 +196,10 @@ bool plugin_remove(struct plugins *plugins, const char *name); /** * Kick of initialization of a plugin. + * + * Returns error string, or NULL. */ -bool plugin_send_getmanifest(struct plugin *p); +const char *plugin_send_getmanifest(struct plugin *p); /** * Kick of initialization of all plugins which need it/ diff --git a/lightningd/plugin_control.c b/lightningd/plugin_control.c index 96d10daa1..e78d1b620 100644 --- a/lightningd/plugin_control.c +++ b/lightningd/plugin_control.c @@ -59,6 +59,7 @@ static struct command_result * plugin_dynamic_start(struct command *cmd, const char *plugin_path) { struct plugin *p = plugin_register(cmd->ld->plugins, plugin_path, cmd); + const char *err; if (!p) return command_fail(cmd, JSONRPC2_INVALID_PARAMS, @@ -66,10 +67,11 @@ plugin_dynamic_start(struct command *cmd, const char *plugin_path) plugin_path); /* This will come back via plugin_cmd_killed or plugin_cmd_succeeded */ - if (!plugin_send_getmanifest(p)) + err = plugin_send_getmanifest(p); + if (err) return command_fail(cmd, PLUGIN_ERROR, - "%s: failed to open: %s", - plugin_path, strerror(errno)); + "%s: %s", + plugin_path, err); return command_still_pending(cmd); }