Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lightningd/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ void channel_set_owner(struct channel *channel, struct subd *owner,
if (old_owner) {
subd_release_channel(old_owner, channel);
if (channel->connected && !connects_to_peer(owner)) {
u8 *msg = towire_connectctl_peer_disconnected(NULL,
&channel->peer->id);
subd_send_msg(channel->peer->ld->connectd, take(msg));
/* If shutting down, connectd no longer exists,
* and we should not transfer peer to connectd.
* Only transfer to connectd if connectd is
* there to be transferred to.
*/
if (channel->peer->ld->connectd) {
u8 *msg;
msg = towire_connectctl_peer_disconnected(
NULL,
&channel->peer->id);
subd_send_msg(channel->peer->ld->connectd,
take(msg));
}
}

if (reconnect) {
Expand Down
6 changes: 3 additions & 3 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ static void shutdown_subdaemons(struct lightningd *ld)
close(ld->hsm_fd);
/*~ The three "global" daemons, which we shutdown explicitly: we
* give them 10 seconds to exit gracefully before killing them. */
subd_shutdown(ld->connectd, 10);
subd_shutdown(ld->gossip, 10);
subd_shutdown(ld->hsm, 10);
ld->connectd = subd_shutdown(ld->connectd, 10);
ld->gossip = subd_shutdown(ld->gossip, 10);
ld->hsm = subd_shutdown(ld->hsm, 10);

/* Now we free all the HTLCs */
free_htlcs(ld, NULL);
Expand Down
6 changes: 3 additions & 3 deletions lightningd/subd.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ void subd_req_(const tal_t *ctx,
add_req(ctx, sd, type, num_fds_in, replycb, replycb_data);
}

void subd_shutdown(struct subd *sd, unsigned int seconds)
struct subd *subd_shutdown(struct subd *sd, unsigned int seconds)
{
log_debug(sd->log, "Shutting down");

Expand All @@ -761,7 +761,7 @@ void subd_shutdown(struct subd *sd, unsigned int seconds)
/* Wait for a while. */
while (seconds) {
if (waitpid(sd->pid, NULL, WNOHANG) > 0) {
return;
return (struct subd*) tal_free(sd);
}
sleep(1);
seconds--;
Expand All @@ -770,7 +770,7 @@ void subd_shutdown(struct subd *sd, unsigned int seconds)
/* Didn't die? This will kill it harder */
sd->must_not_exit = false;
destroy_subd(sd);
tal_free(sd);
return (struct subd*) tal_free(sd);
}

void subd_release_channel(struct subd *owner, void *channel)
Expand Down
6 changes: 5 additions & 1 deletion lightningd/subd.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,12 @@ void subd_release_channel(struct subd *owner, void *channel);
*
* This closes the fd to the subdaemon, and gives it a little while to exit.
* The @finished callback will never be called.
*
* Return value is null, so pattern should be:
*
* sd = subd_shutdown(sd, 10);
*/
void subd_shutdown(struct subd *subd, unsigned int seconds);
struct subd *subd_shutdown(struct subd *subd, unsigned int seconds);

/* Ugly helper to get full pathname of the current binary. */
const char *find_my_abspath(const tal_t *ctx, const char *argv0);
Expand Down