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;
|
char **cmd;
|
||||||
int stdin, stdout;
|
int stdin, stdout;
|
||||||
@@ -1242,7 +1242,7 @@ bool plugin_send_getmanifest(struct plugin *p)
|
|||||||
cmd[1] = "--debugger";
|
cmd[1] = "--debugger";
|
||||||
p->pid = pipecmdarr(&stdin, &stdout, &pipecmd_preserve, cmd);
|
p->pid = pipecmdarr(&stdin, &stdout, &pipecmd_preserve, cmd);
|
||||||
if (p->pid == -1)
|
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);
|
log_debug(p->plugins->log, "started(%u) %s", p->pid, p->cmd);
|
||||||
p->buffer = tal_arr(p, char, 64);
|
p->buffer = tal_arr(p, char, 64);
|
||||||
@@ -1268,7 +1268,7 @@ bool plugin_send_getmanifest(struct plugin *p)
|
|||||||
plugin_manifest_timeout, p);
|
plugin_manifest_timeout, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool plugins_send_getmanifest(struct plugins *plugins)
|
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 */
|
/* Spawn the plugin processes before entering the io_loop */
|
||||||
list_for_each_safe(&plugins->plugins, p, next, list) {
|
list_for_each_safe(&plugins->plugins, p, next, list) {
|
||||||
|
const char *err;
|
||||||
|
|
||||||
if (p->plugin_state != UNCONFIGURED)
|
if (p->plugin_state != UNCONFIGURED)
|
||||||
continue;
|
continue;
|
||||||
if (plugin_send_getmanifest(p)) {
|
err = plugin_send_getmanifest(p);
|
||||||
|
if (!err) {
|
||||||
sent = true;
|
sent = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,8 +196,10 @@ bool plugin_remove(struct plugins *plugins, const char *name);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Kick of initialization of a plugin.
|
* 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/
|
* 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)
|
plugin_dynamic_start(struct command *cmd, const char *plugin_path)
|
||||||
{
|
{
|
||||||
struct plugin *p = plugin_register(cmd->ld->plugins, plugin_path, cmd);
|
struct plugin *p = plugin_register(cmd->ld->plugins, plugin_path, cmd);
|
||||||
|
const char *err;
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
@@ -66,10 +67,11 @@ plugin_dynamic_start(struct command *cmd, const char *plugin_path)
|
|||||||
plugin_path);
|
plugin_path);
|
||||||
|
|
||||||
/* This will come back via plugin_cmd_killed or plugin_cmd_succeeded */
|
/* 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,
|
return command_fail(cmd, PLUGIN_ERROR,
|
||||||
"%s: failed to open: %s",
|
"%s: %s",
|
||||||
plugin_path, strerror(errno));
|
plugin_path, err);
|
||||||
|
|
||||||
return command_still_pending(cmd);
|
return command_still_pending(cmd);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user