Skip to content

Commit

Permalink
lightningd: tell connectd we're shutting down.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell authored and vincenzopalazzo committed Feb 5, 2023
1 parent 2209d01 commit 4560781
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lightningd/connect_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lightningd/connect_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,9 @@ int main(int argc, char *argv[])
/* 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;

Expand Down
3 changes: 3 additions & 0 deletions lightningd/test/run-find_my_abspath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down

0 comments on commit 4560781

Please sign in to comment.