MCPcopy Create free account
hub / github.com/ElementsProject/lightning / gossmap_compact

Function gossmap_compact

gossipd/gossmap_manage.c:1763–1856  ·  view source on GitHub ↗

Returns false if already running */

Source from the content-addressed store, hash-verified

1761}
1762/* Returns false if already running */
1763static bool gossmap_compact(struct gossmap_manage *gm, bool dev_compact)
1764{
1765 int childin[2], execfail[2], childout[2];
1766 int saved_errno;
1767
1768 /* Only one at a time please! */
1769 if (gm->compactd)
1770 return false;
1771
1772 /* This checks contents: we want to make sure compactd sees an
1773 * up-to-date version. */
1774 gossmap_manage_get_gossmap(gm);
1775
1776 gm->compactd = tal(gm, struct compactd);
1777 for (size_t i = 0; i < ARRAY_SIZE(gm->compactd->uuid); i++)
1778 gm->compactd->uuid[i] = pseudorand(256);
1779
1780 gm->compactd->old_size = gossip_store_len_written(gm->gs);
1781 status_debug("Executing lightning_gossip_compactd %s %s %s %s",
1782 GOSSIP_STORE_FILENAME,
1783 GOSSIP_STORE_COMPACT_FILENAME,
1784 tal_fmt(tmpctx, "%"PRIu64, gm->compactd->old_size),
1785 tal_hexstr(tmpctx, gm->compactd->uuid, sizeof(gm->compactd->uuid)));
1786
1787 if (pipe(childin) != 0 || pipe(childout) != 0 || pipe(execfail) != 0)
1788 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1789 "Could not create pipes for compactd: %s",
1790 strerror(errno));
1791
1792 if (fcntl(execfail[1], F_SETFD, fcntl(execfail[1], F_GETFD)
1793 | FD_CLOEXEC) < 0)
1794 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1795 "Could not set cloexec on compactd fd: %s",
1796 strerror(errno));
1797
1798 gm->compactd->pid = fork();
1799 if (gm->compactd->pid < 0)
1800 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1801 "Could not fork for compactd: %s",
1802 strerror(errno));
1803
1804 if (gm->compactd->pid == 0) {
1805 close(childin[0]);
1806 close(childout[1]);
1807 close(execfail[0]);
1808
1809 /* In practice, low fds are all open, so we don't have
1810 * to handle those horrible cases */
1811 assert(childin[1] > 2);
1812 assert(childout[0] > 2);
1813 if (dup2(childin[1], STDOUT_FILENO) == -1)
1814 err(1, "Failed to duplicate fd to stdout");
1815 close(childin[1]);
1816 if (dup2(childout[0], STDIN_FILENO) == -1)
1817 err(1, "Failed to duplicate fd to stdin");
1818 close(childout[0]);
1819 closefrom_limit(0);
1820 closefrom(3);

Calls 7

gossip_store_len_writtenFunction · 0.85
tal_hexstrFunction · 0.85
errFunction · 0.85
closefromFunction · 0.85
status_failedFunction · 0.50
closefrom_limitFunction · 0.50

Tested by

no test coverage detected