subd: clear transient billboard on start and shutdown.

Use NULL on the callback to mean "clear the slot", and call it.

We have do this in two places: the old daemon might die, or the new
daemon might start first.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-02-23 16:23:47 +10:30
committed by Christian Decker
parent 26b004e5af
commit cca0a5412e
3 changed files with 14 additions and 6 deletions

View File

@@ -326,12 +326,14 @@ void channel_set_billboard(struct channel *channel, bool perm, const char *str)
p = &channel->billboard.permanent[channel->state];
else
p = &channel->billboard.transient;
tal_free(*p);
*p = tal_free(*p);
if (str) {
*p = tal_fmt(channel, "%s:%s", channel_state_name(channel), str);
if (taken(str))
tal_free(str);
}
}
void channel_fail_transient(struct channel *channel, const char *fmt, ...)
{

View File

@@ -490,7 +490,8 @@ static void opening_channel_set_billboard(struct uncommitted_channel *uc,
bool perm UNUSED,
const char *happenings TAKES)
{
tal_free(uc->transient_billboard);
uc->transient_billboard = tal_free(uc->transient_billboard);
if (happenings)
uc->transient_billboard = tal_strdup(uc, happenings);
}

View File

@@ -585,6 +585,8 @@ static void destroy_subd(struct subd *sd)
struct db *db = sd->ld->wallet->db;
bool outer_transaction;
/* Clear any transient messages in billboard */
sd->billboardcb(channel, false, NULL);
sd->channel = NULL;
/* We can be freed both inside msg handling, or spontaneously. */
@@ -695,6 +697,9 @@ static struct subd *new_subd(struct lightningd *ld,
log_debug(sd->log, "pid %u, msgfd %i", sd->pid, msg_fd);
/* Clear any old transient message. */
if (billboardcb)
billboardcb(sd->channel, false, NULL);
return sd;
}