diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 4d84ab3f9..602ed9441 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -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; +} diff --git a/lightningd/plugin.h b/lightningd/plugin.h index 47b118786..50e6e5dc2 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -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. */