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