| 2619 | } |
| 2620 | |
| 2621 | static void dev_save_plugin_io(struct plugins *plugins, |
| 2622 | const char *type, |
| 2623 | const char *name, |
| 2624 | const char *buf, size_t len) |
| 2625 | { |
| 2626 | static size_t counter; |
| 2627 | static u64 starttime; |
| 2628 | const char *file; |
| 2629 | int fd; |
| 2630 | |
| 2631 | if (!plugins->dev_save_io) |
| 2632 | return; |
| 2633 | |
| 2634 | /* If we reexec, we still want unique names */ |
| 2635 | if (!starttime) { |
| 2636 | struct timemono start = time_mono(); |
| 2637 | starttime = start.ts.tv_sec * 1000000 + start.ts.tv_nsec / 1000; |
| 2638 | } |
| 2639 | |
| 2640 | file = path_join(tmpctx, plugins->dev_save_io, |
| 2641 | take(tal_fmt(NULL, "%s-%s-%u-%"PRIu64"-%zu", |
| 2642 | type, name, |
| 2643 | (unsigned int)getpid(), |
| 2644 | starttime, |
| 2645 | counter++))); |
| 2646 | fd = open(file, O_CREAT|O_EXCL|O_WRONLY, 0600); |
| 2647 | if (fd < 0 || !write_all(fd, buf, len)) |
| 2648 | fatal("Writing --dev-save-plugin-io %s: %s", |
| 2649 | file, strerror(errno)); |
| 2650 | close(fd); |
| 2651 | } |
| 2652 | |
| 2653 | void dev_save_plugin_io_in(struct plugins *plugins, |
| 2654 | const char *type, |
no test coverage detected