log: add ltmp convenience context.

It's sometimes nicer where you don't have a convenient tmpctx.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-09-12 21:19:37 +09:30 committed by Christian Decker
parent dfa062b06a
commit afabbe0cb0
2 changed files with 14 additions and 0 deletions

View File

@ -108,6 +108,10 @@ struct log_book *new_log_book(const tal_t *ctx,
lr->init_time = time_now();
list_head_init(&lr->log);
/* In case ltmp not initialized, do so now. */
if (!ltmp)
ltmp = tal_tmpctx(lr);
return lr;
}
@ -185,6 +189,12 @@ static void add_entry(struct log *log, struct log_entry *l)
log_debug(log, "Log pruned %zu entries (mem %zu -> %zu)",
deleted, old_mem, log->lr->mem_used);
}
/* Free up temporaries now if any */
if (tal_first(ltmp)) {
tal_free(ltmp);
ltmp = tal_tmpctx(log->lr);
}
}
static struct log_entry *new_log_entry(struct log *log, enum log_level level)

View File

@ -129,6 +129,10 @@ void log_dump_to_file(int fd, const struct log_book *lr);
void opt_register_logging(struct log *log);
void crashlog_activate(struct log *log);
/* Convenience parent for temporary allocations (eg. type_to_string)
* during log calls; freed after every log_*() */
const tal_t *ltmp;
/* Before the crashlog is activated, just prints to stderr. */
void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...);
#endif /* LIGHTNING_LIGHTNINGD_LOG_H */