| 2124 | } |
| 2125 | |
| 2126 | void shutdown_plugins(struct lightningd *ld) |
| 2127 | { |
| 2128 | struct plugin *p, *next; |
| 2129 | |
| 2130 | /* Tell them all to shutdown; if they care. */ |
| 2131 | list_for_each_safe(&ld->plugins->plugins, p, next, list) { |
| 2132 | /* Kill immediately, deletes self from list. */ |
| 2133 | if (p->plugin_state != INIT_COMPLETE || !notify_plugin_shutdown(ld, p)) |
| 2134 | tal_free(p); |
| 2135 | } |
| 2136 | |
| 2137 | /* If anyone was interested in shutdown, give them time. */ |
| 2138 | if (!list_empty(&ld->plugins->plugins)) { |
| 2139 | struct timers *timer; |
| 2140 | struct timer *expired; |
| 2141 | |
| 2142 | /* 30 seconds should do it, use a clean timers struct */ |
| 2143 | timer = tal(NULL, struct timers); |
| 2144 | timers_init(timer, time_mono()); |
| 2145 | new_reltimer(timer, timer, time_from_sec(30), NULL, NULL); |
| 2146 | |
| 2147 | void *ret = io_loop(timer, &expired); |
| 2148 | assert(ret == NULL || ret == destroy_plugin); |
| 2149 | |
| 2150 | /* Report and free remaining plugins. */ |
| 2151 | while (!list_empty(&ld->plugins->plugins)) { |
| 2152 | p = list_pop(&ld->plugins->plugins, struct plugin, list); |
| 2153 | log_debug(ld->log, |
| 2154 | "%s: failed to self-terminate in time, killing.", |
| 2155 | p->shortname); |
| 2156 | tal_free(p); |
| 2157 | } |
| 2158 | } |
| 2159 | } |
no test coverage detected