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