| 248 | } |
| 249 | |
| 250 | static void destroy_plugin(struct plugin *p) |
| 251 | { |
| 252 | struct jsonrpc_request **reqs; |
| 253 | |
| 254 | list_del(&p->list); |
| 255 | |
| 256 | /* Don't have p->conn destructor run. */ |
| 257 | if (p->stdout_conn) |
| 258 | io_set_finish(p->stdout_conn, NULL, NULL); |
| 259 | |
| 260 | /* Gather all pending RPC calls (we can't iterate as we delete!) */ |
| 261 | reqs = tal_arr(NULL, struct jsonrpc_request *, 0); |
| 262 | strmap_iterate(&p->pending_requests, request_add, &reqs); |
| 263 | |
| 264 | /* Don't fail requests if we're exiting anyway! */ |
| 265 | if (p->plugins->ld->state != LD_STATE_SHUTDOWN) { |
| 266 | for (size_t i = 0; i < tal_count(reqs); i++) |
| 267 | plugin_terminated_fail_req(p, reqs[i]); |
| 268 | } |
| 269 | /* Now free all the requests */ |
| 270 | tal_free(reqs); |
| 271 | |
| 272 | /* Remove any topics from the hash table */ |
| 273 | for (size_t i = 0; i < tal_count(p->subscriptions); i++) { |
| 274 | plugin_subscription_htable_del(p->plugins->subscriptions, |
| 275 | &p->subscriptions[i]); |
| 276 | } |
| 277 | |
| 278 | /* If this was last one manifests were waiting for, handle deps */ |
| 279 | if (p->plugin_state == AWAITING_GETMANIFEST_RESPONSE) |
| 280 | check_plugins_manifests(p->plugins, p->plugins->ld->log); |
| 281 | |
| 282 | /* Daemon shutdown overrules plugin's importance; aborts init checks */ |
| 283 | if (p->plugins->ld->state == LD_STATE_SHUTDOWN) { |
| 284 | /* But return if this was the last plugin! */ |
| 285 | if (list_empty(&p->plugins->plugins)) { |
| 286 | log_debug(p->plugins->ld->log, "io_break: %s", __func__); |
| 287 | io_break(destroy_plugin); |
| 288 | } |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | /* If this was the last one init was waiting for, handle cmd replies */ |
| 293 | if (p->plugin_state == AWAITING_INIT_RESPONSE) |
| 294 | check_plugins_initted(p->plugins); |
| 295 | |
| 296 | /* Now check if the dying plugin is important. */ |
| 297 | if (p->important) { |
| 298 | log_broken(p->log, |
| 299 | "Plugin marked as important, " |
| 300 | "shutting down lightningd!"); |
| 301 | lightningd_exit(p->plugins->ld, 1); |
| 302 | } |
| 303 | |
| 304 | if (tal_count(p->custom_msgs)) |
| 305 | tell_connectd_custommsgs(p->plugins); |
| 306 | |
| 307 | notify_plugin_stopped(p->plugins->ld, p); |
nothing calls this directly
no test coverage detected