lightningd: tell connectd we're shutting down.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-02-04 15:46:24 +10:30 committed by Vincenzo Palazzo
parent 2209d0149f
commit 456078150a
4 changed files with 33 additions and 0 deletions

View File

@ -522,6 +522,32 @@ static void handle_custommsg_in(struct lightningd *ld, const u8 *msg)
plugin_hook_call_custommsg(ld, NULL, p);
}
static void connectd_start_shutdown_reply(struct subd *connectd,
const u8 *reply,
const int *fds UNUSED,
void *unused UNUSED)
{
if (!fromwire_connectd_start_shutdown_reply(reply))
fatal("Bad connectd_start_shutdown_reply: %s",
tal_hex(reply, reply));
/* Break out of loop now, so we can continue shutdown. */
log_debug(connectd->ld->log, "io_break: %s", __func__);
io_break(connectd);
}
void connectd_start_shutdown(struct subd *connectd)
{
const u8 *msg = towire_connectd_start_shutdown(NULL);
subd_req(connectd, connectd, take(msg), -1, 0,
connectd_start_shutdown_reply, NULL);
/* Wait for shutdown_reply. Note that since we're shutting down,
* start_json_stream can io_break too! */
while (io_loop(NULL, NULL) != connectd);
}
static unsigned connectd_msg(struct subd *connectd, const u8 *msg, const int *fds)
{
enum connectd_wire t = fromwire_peektype(msg);

View File

@ -17,6 +17,7 @@ struct wireaddr_internal;
/* Returns fd for gossipd to talk to connectd */
int connectd_init(struct lightningd *ld);
void connectd_activate(struct lightningd *ld);
void connectd_start_shutdown(struct subd *connectd);
void try_reconnect(const tal_t *ctx,
struct peer *peer,

View File

@ -1235,6 +1235,9 @@ stop:
/* Stop *new* JSON RPC requests. */
jsonrpc_stop_listening(ld->jsonrpc);
/* Stop new connectd requests */
connectd_start_shutdown(ld->connectd);
/* Give permission for things to get destroyed without getting upset. */
ld->state = LD_STATE_SHUTDOWN;

View File

@ -20,6 +20,9 @@ void connectd_activate(struct lightningd *ld UNNEEDED)
/* Generated stub for connectd_init */
int connectd_init(struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "connectd_init called!\n"); abort(); }
/* Generated stub for connectd_start_shutdown */
void connectd_start_shutdown(struct subd *connectd UNNEEDED)
{ fprintf(stderr, "connectd_start_shutdown called!\n"); abort(); }
/* Generated stub for daemon_poll */
int daemon_poll(struct pollfd *fds UNNEEDED, nfds_t nfds UNNEEDED, int timeout UNNEEDED)
{ fprintf(stderr, "daemon_poll called!\n"); abort(); }