mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
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 <rusty@rustcorp.com.au>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user