| 1670 | } |
| 1671 | |
| 1672 | static void compactd_done(struct io_conn *unused, struct gossmap_manage *gm) |
| 1673 | { |
| 1674 | int status; |
| 1675 | struct stat st; |
| 1676 | |
| 1677 | if (waitpid(gm->compactd->pid, &status, 0) < 0) |
| 1678 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 1679 | "Waiting for %u: %s", |
| 1680 | (unsigned int)gm->compactd->pid, |
| 1681 | strerror(errno)); |
| 1682 | |
| 1683 | if (!WIFEXITED(status)) { |
| 1684 | compactd_broken(gm, "compactd failed with signal %u", |
| 1685 | WTERMSIG(status)); |
| 1686 | goto failed; |
| 1687 | } |
| 1688 | if (WEXITSTATUS(status) != 0) { |
| 1689 | compactd_broken(gm, "compactd exited with status %u", |
| 1690 | WEXITSTATUS(status)); |
| 1691 | goto failed; |
| 1692 | } |
| 1693 | |
| 1694 | if (stat(GOSSIP_STORE_COMPACT_FILENAME, &st) != 0) { |
| 1695 | compactd_broken(gm, "compactd did not create file? %s", |
| 1696 | strerror(errno)); |
| 1697 | goto failed; |
| 1698 | } |
| 1699 | |
| 1700 | status_debug("compaction done: %"PRIu64" -> %"PRIu64" bytes", |
| 1701 | gm->compactd->old_size, (u64)st.st_size); |
| 1702 | |
| 1703 | /* We will reload dying_channels as we reopen */ |
| 1704 | tal_free(gm->dying_channels); |
| 1705 | gm->dying_channels = tal_arr(gm, struct chan_dying, 0); |
| 1706 | |
| 1707 | /* Switch gossmap to new one, as a sanity check (rather than |
| 1708 | * writing end marker and letting it reopen) */ |
| 1709 | tal_free(gm->raw_gossmap); |
| 1710 | gm->raw_gossmap = gossmap_load_initial(gm, GOSSIP_STORE_COMPACT_FILENAME, |
| 1711 | st.st_size, |
| 1712 | gossmap_logcb, |
| 1713 | gossmap_add_dying_chan, |
| 1714 | gm); |
| 1715 | if (!gm->raw_gossmap) |
| 1716 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 1717 | "compacted gossip_store is invalid"); |
| 1718 | |
| 1719 | if (rename(GOSSIP_STORE_COMPACT_FILENAME, GOSSIP_STORE_FILENAME) != 0) |
| 1720 | status_failed(STATUS_FAIL_INTERNAL_ERROR, |
| 1721 | "Error renaming gossip store: %s", |
| 1722 | strerror(errno)); |
| 1723 | |
| 1724 | /* Now append record to old one, so everyone will switch */ |
| 1725 | gossip_store_add(gm->gs, |
| 1726 | towire_gossip_store_ended(tmpctx, st.st_size, gm->compactd->uuid), |
| 1727 | 0); |
| 1728 | gossip_store_reopen(gm->gs); |
| 1729 | if (gm->compactd->dev_compact) |
nothing calls this directly
no test coverage detected