diff --git a/CHANGELOG.md b/CHANGELOG.md index 72d62bc70..0d126b5fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. their capacity or their `htlc_minimum_msat` parameter (#1777) - We now try to connect to all known addresses for a peer, not just the one given or the first one announced. +- Crash logs are now placed one-per file like `crash.log.20180822233752` ### Deprecated diff --git a/lightningd/log.c b/lightningd/log.c index 13ed30a22..1175baa6c 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -569,18 +569,22 @@ static void log_dump_to_file(int fd, const struct log_book *lr) void log_backtrace_exit(void) { int fd; - char logfile[sizeof("/tmp/lightning-crash.log.%u") + STR_MAX_CHARS(int)]; + char timebuf[sizeof("YYYYmmddHHMMSS")]; + char logfile[sizeof("/tmp/lightning-crash.log.") + sizeof(timebuf)]; + struct timeabs time = time_now(); + + strftime(timebuf, sizeof(timebuf), "%Y%m%d%H%M%S", gmtime(&time.ts.tv_sec)); if (!crashlog) return; /* We expect to be in config dir. */ - snprintf(logfile, sizeof(logfile), "crash.log.%u", getpid()); + snprintf(logfile, sizeof(logfile), "crash.log.%s", timebuf); fd = open(logfile, O_WRONLY|O_CREAT|O_TRUNC, 0600); if (fd < 0) { snprintf(logfile, sizeof(logfile), - "/tmp/lightning-crash.log.%u", getpid()); + "/tmp/lightning-crash.log.%s", timebuf); fd = open(logfile, O_WRONLY|O_CREAT|O_TRUNC, 0600); } diff --git a/tests/test_misc.py b/tests/test_misc.py index a364bff80..ed217eac3 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -875,8 +875,11 @@ def test_logging(node_factory): def test_crashlog(node_factory): l1 = node_factory.get_node(may_fail=True) - crashpath = os.path.join(l1.daemon.lightning_dir, - 'crash.log.{}'.format(l1.daemon.proc.pid)) - assert not os.path.exists(crashpath) + def has_crash_log(n): + files = os.listdir(n.daemon.lightning_dir) + crashfiles = [f for f in files if 'crash.log' in f] + return len(crashfiles) > 0 + + assert not has_crash_log(l1) l1.daemon.proc.send_signal(signal.SIGSEGV) - wait_for(lambda: os.path.exists(crashpath)) + wait_for(lambda: has_crash_log(l1))