Commit d065031
dns: ask the port what is running, not just our pidfile (#425)
* dns: ask the port what is running, not just our pidfile
`moshcode dns status` answered "is the bridge running" from its own pidfile
alone. That file only ever describes a bridge this tool started, in this
privilege context, so every other way a bridge reaches 5354 read as
`bridge not running`: a systemd unit, a hand-started `dns start`, or — the
common one — an `enable` that escalated to root and therefore wrote its
pidfile under root's HOME instead of the invoking user's runtime dir.
That was not a cosmetic lie. Status followed it with "routing is in place but
the bridge is not running — Moshpit names will fail" and advised
`sudo moshcode dns enable`. Following that advice starts a second bridge bound
to 127.0.0.1:5354 while the working one holds 0.0.0.0:5354; the kernel
delivers to the more specific socket, so the healthy bridge stops receiving
anything and the machine loses DNS. portHolder's comment already describes
that outage twice over — this is the path that walks into it by following our
own instructions.
So the port gets asked. `bridgePresence` puts both questions that matter, a
Moshpit name and a clearnet one, because a resolver that stopped answering
loses a namespace and one that stopped forwarding takes the box off the
internet. A bridge nothing here started is reported as a bridge, with its pid,
and the alarm now fires on "nothing answers" rather than "our pidfile is
empty". A new warning covers answering-but-not-forwarding, which was
previously invisible from the Moshpit side.
The remedy also drops its `sudo`: the CLI escalates the one step that needs
root, and teaching `sudo moshcode` is how `sudo moshcode update` ends up
reinstalling the tool into /root.
Two supporting fixes:
- pidfilePath honours SUDO_UID, so the escalated run that starts the bridge
records it where the unprivileged runs that ask about it will look. Only
when that runtime dir actually exists — deriving /run/user/<uid> on a
machine without one swaps an unreadable path for a missing one, so macOS
falls through unchanged.
- status uses the injected fetchTlds, like every other caller. Reaching past
it made status the one subcommand untestable without a network.
Verified against a box running the bridge as a systemd unit: before, `not
running` plus the shadowing advice; after, `answering on 127.0.0.1:5354
(pid 1330, bun) — started by something other than \`dns enable\``.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* dns: inject the routing check so status tests do not read the host
The two new status tests passed here and failed on CI, and the tests were
right to fail: `status` read `/etc/systemd/resolved.conf.d/moshpit.conf` off
the real filesystem, so "is this machine routed" was answered by whichever
machine happened to be running the suite. Green on a developer's box with
Moshpit enabled, red on a clean runner.
So `exists` joins the other injected system calls, and the tests state the
routing they are asserting about instead of inheriting it. Adds the case that
was missing on both sides: an unrouted machine with no bridge is not an
emergency and must not print the alarm.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent c0a1751 commit d065031
3 files changed
Lines changed: 360 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
336 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
337 | 353 | | |
338 | 354 | | |
339 | 355 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1742 | 1742 | | |
1743 | 1743 | | |
1744 | 1744 | | |
1745 | | - | |
| 1745 | + | |
1746 | 1746 | | |
1747 | 1747 | | |
1748 | 1748 | | |
| |||
1783 | 1783 | | |
1784 | 1784 | | |
1785 | 1785 | | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
1786 | 1869 | | |
1787 | 1870 | | |
1788 | 1871 | | |
| |||
2151 | 2234 | | |
2152 | 2235 | | |
2153 | 2236 | | |
2154 | | - | |
| 2237 | + | |
2155 | 2238 | | |
2156 | 2239 | | |
2157 | 2240 | | |
| |||
2230 | 2313 | | |
2231 | 2314 | | |
2232 | 2315 | | |
| 2316 | + | |
| 2317 | + | |
2233 | 2318 | | |
2234 | 2319 | | |
2235 | 2320 | | |
| |||
3009 | 3094 | | |
3010 | 3095 | | |
3011 | 3096 | | |
3012 | | - | |
| 3097 | + | |
| 3098 | + | |
| 3099 | + | |
3013 | 3100 | | |
3014 | | - | |
| 3101 | + | |
3015 | 3102 | | |
3016 | 3103 | | |
3017 | 3104 | | |
3018 | 3105 | | |
3019 | | - | |
| 3106 | + | |
| 3107 | + | |
| 3108 | + | |
| 3109 | + | |
| 3110 | + | |
3020 | 3111 | | |
3021 | 3112 | | |
3022 | | - | |
3023 | | - | |
3024 | | - | |
| 3113 | + | |
| 3114 | + | |
| 3115 | + | |
| 3116 | + | |
| 3117 | + | |
| 3118 | + | |
| 3119 | + | |
| 3120 | + | |
| 3121 | + | |
| 3122 | + | |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
| 3127 | + | |
| 3128 | + | |
| 3129 | + | |
| 3130 | + | |
3025 | 3131 | | |
3026 | | - | |
3027 | | - | |
| 3132 | + | |
| 3133 | + | |
3028 | 3134 | | |
3029 | 3135 | | |
3030 | | - | |
| 3136 | + | |
| 3137 | + | |
| 3138 | + | |
3031 | 3139 | | |
3032 | 3140 | | |
3033 | 3141 | | |
| |||
0 commit comments