| 1096 | } |
| 1097 | |
| 1098 | void log_backtrace_exit(void) |
| 1099 | { |
| 1100 | int fd; |
| 1101 | char timebuf[sizeof("YYYYmmddHHMMSS")]; |
| 1102 | char logfile[sizeof("/tmp/lightning-crash.log.") + sizeof(timebuf)]; |
| 1103 | struct timeabs time = clock_time(); |
| 1104 | |
| 1105 | strftime(timebuf, sizeof(timebuf), "%Y%m%d%H%M%S", gmtime(&time.ts.tv_sec)); |
| 1106 | |
| 1107 | if (!crashlog) |
| 1108 | return; |
| 1109 | |
| 1110 | /* We expect to be in config dir. */ |
| 1111 | snprintf(logfile, sizeof(logfile), "crash.log.%s", timebuf); |
| 1112 | |
| 1113 | fd = open(logfile, O_WRONLY|O_CREAT|O_TRUNC, 0600); |
| 1114 | if (fd < 0) { |
| 1115 | snprintf(logfile, sizeof(logfile), |
| 1116 | "/tmp/lightning-crash.log.%s", timebuf); |
| 1117 | fd = open(logfile, O_WRONLY|O_CREAT|O_TRUNC, 0600); |
| 1118 | } |
| 1119 | |
| 1120 | /* Dump entire log. */ |
| 1121 | if (fd >= 0) { |
| 1122 | log_dump_to_file(fd, crashlog->log_book); |
| 1123 | close(fd); |
| 1124 | fprintf(stderr, "Log dumped in %s\n", logfile); |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | void fatal_vfmt(const char *fmt, va_list ap) |
| 1129 | { |
nothing calls this directly
no test coverage detected