From b4f7ce61b4569844d62924579fd95889e42aa684 Mon Sep 17 00:00:00 2001 From: John Barboza Date: Sat, 10 Mar 2018 14:02:33 -0500 Subject: [PATCH] Append to crash log instead of creating new one Multiple crashes accumulate in case you have some kind of auto-restart for daemons. --- lightningd/log.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lightningd/log.c b/lightningd/log.c index dd1723616..e259dbc7c 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -510,7 +510,7 @@ static void log_crash(int sig) /* We expect to be in config dir. */ logfile = "crash.log"; - fd = open(logfile, O_WRONLY|O_CREAT, 0600); + fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0600); if (fd < 0) { logfile = "/tmp/lightning-crash.log"; fd = open(logfile, O_WRONLY|O_CREAT, 0600); @@ -554,9 +554,13 @@ void log_dump_to_file(int fd, const struct log_book *lr) { const struct log_entry *i; char buf[100]; + int len; struct log_data data; time_t start; + write_all(fd, "Start of new crash log\n", + strlen("Start of new crash log\n")); + i = list_top(&lr->log, const struct log_entry, list); if (!i) { write_all(fd, "0 bytes:\n\n", strlen("0 bytes:\n\n")); @@ -564,8 +568,8 @@ void log_dump_to_file(int fd, const struct log_book *lr) } start = lr->init_time.ts.tv_sec; - sprintf(buf, "%zu bytes, %s", lr->mem_used, ctime(&start)); - write_all(fd, buf, strlen(buf)); + len = sprintf(buf, "%zu bytes, %s", lr->mem_used, ctime(&start)); + write_all(fd, buf, len); /* ctime includes \n... WTF? */ data.prefix = "";