plugin: plugin_exclusive_loop helper to service one plugin synchronously.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-03-18 13:10:32 +10:30
parent a319439957
commit 3729ad9914
2 changed files with 26 additions and 0 deletions

View File

@@ -1053,3 +1053,21 @@ void plugin_request_send(struct plugin *plugin,
* pointer here */
req->stream = NULL;
}
void *plugin_exclusive_loop(struct plugin *plugin)
{
void *ret;
io_conn_out_exclusive(plugin->stdin_conn, true);
io_conn_exclusive(plugin->stdout_conn, true);
/* We don't service timers here, either! */
ret = io_loop(NULL, NULL);
io_conn_out_exclusive(plugin->stdin_conn, false);
if (io_conn_exclusive(plugin->stdout_conn, false))
fatal("Still io_exclusive after removing plugin %s?",
plugin->cmd);
return ret;
}

View File

@@ -79,6 +79,14 @@ void json_add_opt_plugins(struct json_stream *response,
const struct plugins *plugins);
/**
* Used by db hooks which can't have any other I/O while talking to plugin.
*
* Returns output of io_loop() (ie. whatever gets passed to io_break()
* to end exclusive loop).
*/
void *plugin_exclusive_loop(struct plugin *plugin);
/**
* Add a directory to the plugin path to automatically load plugins.
*/