| 282 | } |
| 283 | |
| 284 | static void add_entry(struct log_book *log, |
| 285 | const struct log_hdr *hdr, |
| 286 | const char *msg, |
| 287 | const u8 *io) |
| 288 | { |
| 289 | void *buf1, *buf2; |
| 290 | size_t buf1len, buf2len; |
| 291 | size_t needed = sizeof(*hdr) + hdr->msglen + hdr->iolen; |
| 292 | assert(needed < sizeof(log->ringbuf)); |
| 293 | |
| 294 | while (ringbuf_avail(log) < needed) |
| 295 | del_front_log(log); |
| 296 | |
| 297 | ringbuf_span(log, log->ringbuf_end, sizeof(*hdr), &buf1, &buf1len, &buf2, &buf2len); |
| 298 | log->ringbuf_end += copy_to(buf1, buf1len, buf2, buf2len, hdr, sizeof(*hdr)); |
| 299 | ringbuf_span(log, log->ringbuf_end, hdr->msglen, &buf1, &buf1len, &buf2, &buf2len); |
| 300 | log->ringbuf_end += copy_to(buf1, buf1len, buf2, buf2len, msg, hdr->msglen); |
| 301 | ringbuf_span(log, log->ringbuf_end, hdr->iolen, &buf1, &buf1len, &buf2, &buf2len); |
| 302 | log->ringbuf_end += copy_to(buf1, buf1len, buf2, buf2len, io, hdr->iolen); |
| 303 | } |
| 304 | |
| 305 | static const char *level_prefix(enum log_level level) |
| 306 | { |
no test coverage detected