Sync network time when a connection comes up

This commit is contained in:
Luxferre committed 2026-11-07 21:53:07 +02:00
1 parent 38d54f10ff
commit 9ac39ce6bf
13 files changed
+365 -8

No files matched your search

+87 -3
View File
@@ -144,7 +144,9 @@ msm-modem-uim-selection msm8909-modem-wwan-port networkmanager postmarketos-zram
rfkill rmtfs sshd tinydm udev-postmount wpa_supplicant` (no `bluetooth`, no `zram-init`).
- `chronyd` running (2 procs) with `pool pool.ntp.org iburst`, `cmdport 0`, `rtcsync`,
`makestep 1 -1`. `chronyc` unusable (`cmdport 0`); after 43 h uptime it is almost certainly at
`makestep 1 -1`. `cmdport 0` closes the UDP command port but leaves chronyd's
root-only Unix socket (`/run/chrony/chronyd.sock`) available for privileged
`chronyc` commands (verified in section 16); after 43 h uptime it is almost certainly at
`maxpoll` ≈ 1024 s, not the initial 64 s.
- `superd` started **without `-l /dev/null`** → the shipped user hook
(`~/.config/sxmo/hooks/sxmo_hook_start.sh`) wins over the default hook and the zero-log
@@ -249,7 +251,7 @@ Ordered by expected impact, with measured evidence. Regression risks are stated.
| **U3** | **`statusbar_periodics`**: `sxmo_run_aligned.sh 60 sxmo_hook_statusbar.sh periodics` is running and its guard passes. Replace `mmcli -m any -J`, `nmcli -t con show --active`, `nmcli ... device wifi list`, `rfkill list wifi`, `xsetroot -name` with D-Bus `PropertiesChanged` signals, or raise to ≥300 s and only `xsetroot` on change. | Removes a 60 s QMI/D-Bus/process burst and a full dwm bar redraw (SPI frame). | Statusbar icons lag up to the new interval. |
| **U4** | **Battery udev path**: filter `85-bananarchy-battery.rules` to `KERNEL=="pm8916-bms-vm"`/`ENV{POWER_SUPPLY_NAME}`, drop the `(sleep 2; ... recheck)` fork, avoid `su` per event. | Measured 2 uevents/min; removes the `su`/`sleep` forks. Lower priority than previously stated. | Charging icon must still update instantly on plug/unplug (keep the charger event). |
| **U5** | **Bluetooth (latent)**: set `AutoEnable=false`, finite `DiscoverableTimeout`/`PairableTimeout`, `ControllerMode=bredr`, and keep BT out of the default runlevel. | BT is already off (soft-blocked, daemon not running) — **no current saving today**; this prevents a future drain when a user enables BT. | BT must still auto-reconnect when explicitly enabled. |
| **U6** | **chronyd**: remove from the default runlevel or set `minpoll 12 maxpoll 16`; rely on `rtcsync`/RTC (`osclock`, `swclock-offset-boot` are already in the boot runlevel). | Measured running with `pool pool.ntp.org iburst`, but after 43 h uptime it is at ~1024 s polls → **low priority**. Removes a daemon and occasional DNS/NTP Wi-Fi wakeups. | Clock drift without NTP. |
| **U6** | **chronyd**: remove from the default runlevel or set `minpoll 12 maxpoll 16`; rely on `rtcsync`/RTC (`osclock`, `swclock-offset-boot` are already in the boot runlevel). | Measured running with `pool pool.ntp.org iburst`, but after 43 h uptime it is at ~1024 s polls → **low priority**. Removes a daemon and occasional DNS/NTP Wi-Fi wakeups. | Clock drift without NTP. **Refined in section 16**: removing `iburst` broke the initial sync entirely, so `iburst` was restored and a network-up hook was added; the long steady-state polls are unchanged. |
| **U7** | ~~Duplicate `wpa_supplicant` / respawn storm~~ | **Removed — see C1.** One stable `-u` instance; the `yesno` typo is harmless. Optionally fix the cosmetic typo. | None. |
| **U8** | **NetworkManager**: add `[device] wifi.scan-interval=600` (no override exists today), `ipv6.method=ignore` for Wi-Fi profiles, keep `wifi.powersave=3` and `connectivity.enabled=false`. | Fewer roaming scans and IPv6 ND/MLD wakeups (measured IPv6 active on wlan0). | Roaming responsiveness; IPv6-only networks. |
| **U9** | **DSDS/modem userspace**: make `dsds-daemon` `poll_stored_sms` (600 s when unlocked) purely event-driven (WMS `NEW_MESSAGE` indications), add backoff on its `time.sleep(2)` exception loop, make `--dpm-open-port` on-demand, and add a "DSDS power-save" toggle (disable secondary subscription / prefer 2G / single-standby while Wi-Fi is the default route). | Measured DSDS active with LTE+GSM, no data bearer, DPM port open, `drx-cycle`/`mico-mode` unset. Directly reduces baseband wakeups. | Must not lose SIM2 calls/SMS; gate on user preference. |
@@ -363,7 +365,7 @@ few places where the regression checks mandated by the analysis changed the impl
| U3 | `statusbar_periodics` interval 60 -> 300 s; `sxmo_hook_statusbar.sh periodics` drops `mmcli`/`nmcli`/`rfkill` polls and only calls `xsetroot` when the status string changes. |
| U4 | udev rule filtered to the two PM8916 supplies; `(sleep 2; ... recheck)` fork removed from `sxmo_hook_battery.sh`. |
| U5 | `AutoEnable=false`, finite discoverable/pairable timeouts, `ControllerMode=bredr`, fewer reconnect attempts. BT was already off on the device, so this is a latent fix. |
| U6 | `etc/chrony/chrony.conf` uses `minpoll 12 maxpoll 16` and no `iburst`. |
| U6 | `etc/chrony/chrony.conf` uses `minpoll 12 maxpoll 16` with `iburst` restored; `bananarchy-time-sync.sh` refreshes the pool on network-up (section 16). |
| U7 | Withdrawn (C1); the cosmetic `yesno` typo in `etc/init.d/wpa_supplicant` was fixed anyway. |
| U8 | `[device] wifi.scan-interval=600` in `10-power.conf`; IPv6 disabled on new interfaces (K10). |
| U9 | On-demand DPM port; `dsds-daemon` 600 s -> 1800 s poll and 2 s -> 30 s error backoff; `sxmo_modemmonitor.sh` 10/120 s -> 30/600 s. |
@@ -784,3 +786,85 @@ that is the deliberate trade for its RF saving.
boot-time `0xffff` transient only disappears after a reflash with the
rebuilt image. Reloading `pm8916_bms_vm` at runtime from `/lib/modules`
confirms the new module reports sane voltage and `health=Good`.
---
## 16. Network-up NTP synchronisation (U6 follow-up)
### 16.1 Symptom and measurement
U6 set `pool pool.ntp.org minpoll 12 maxpoll 16` and removed `iburst` to avoid
the startup packet burst. A later live check on the connected Nokia 8110 4G
found the clock at `Mon Jan 12 12:09:59 UTC 1970` with Wi-Fi connected to
`OffOurStreets_`, USB RNDIS up, DNS working (`getent hosts pool.ntp.org`
returned 3 addresses) and `chronyd` reported `started` by OpenRC:
| Probe | Result |
| --- | --- |
| `chronyd` processes | 2, `-f /etc/chrony/chrony.conf -F 1` |
| NTP/chrony UDP sockets | none (no source had an address) |
| `chronyc activity` over the root Unix socket | `4 sources online`, `4 sources with unknown address` |
| `chronyc tracking` | `Reference ID : 00000000 ()`, ref time 1970 |
| `/var/lib/chrony` | `root:root 0750`, empty; chronyd logged `Could not open /var/lib/chrony/chrony.drift.tmp : Permission denied` |
| `chronyd -Q -t 30 ... iburst` | clock wrong by `1793085783 s`, measured in 5 s |
| `chronyd -d -x -t 25 -F 1` with shipped config | no source activity for the whole 25 s |
Three independent causes combined:
1. **DNS is not ready when chronyd starts.** OpenRC's `need net` is satisfied
by NetworkManager `provide net` as soon as the service starts, not when a
connection has a working `resolv.conf`. chronyd resolves pool names once at
startup and does not retry; the four sources stay at `unknown address`.
2. **No `iburst` and `minpoll 12`.** Even with DNS working, the first poll is
scheduled up to 4096 s after startup. Restarting chronyd with the network
already up produced no NTP socket and no clock change within 15 s; adding
`iburst` produced four reachable sources at poll 12 within 6 s.
3. **`cmdport 0` was assumed to disable chronyc entirely.** It only closes the
UDP command port. chronyd 4.9 keeps a root/chrony-only Unix socket at
`/run/chrony/chronyd.sock`; `chronyc` defaults to that socket first, so
privileged commands (`refresh`, `burst`, `online`) work without any key or
network exposure. `chronyc -h 127.0.0.1 refresh` returns `501 Not
authorised`, while `chronyc -h /run/chrony/chronyd.sock refresh` returns
`200 OK`.
A Wi-Fi disconnect/reconnect confirmed NetworkManager dispatcher scripts do
run even though the `networkmanager-dispatcher` OpenRC service is stopped:
D-Bus activates `org.freedesktop.nm_dispatcher`. Events observed:
`connectivity-change`, `dns-change`, `down`, `dns-change`, `dhcp4-change`,
`up`, `connectivity-change`.
### 16.2 Fix
- `etc/chrony/chrony.conf` restores `iburst` and keeps `minpoll 12 maxpoll 16`,
`rtcsync`, `cmdport 0` and `makestep 1 -1`. The startup burst is 4 sources x
a few packets once per boot, negligible next to 4096 s of a wrong clock.
- `usr/bin/bananarchy-time-sync.sh` (root, `doas -n` re-exec) waits for the
chronyd Unix socket, calls `chronyc refresh` until `activity` reports
`0 sources with unknown address`, then `online` and `burst 2/4`. It only
writes its throttle stamp once the pool resolves, so a later network event
can retry. Throttling uses `/proc/uptime` (monotonic): 15 s between attempts
while unsynchronised, 300 s between source refreshes once synchronised, and
a non-blocking `flock` serialises the several dispatcher events that fire
for one connection. `status` and `force` are available from the CLI.
- `etc/NetworkManager/dispatcher.d/20-bananarchy-time-sync.sh` handles
`up`, `dhcp4-change`, `dhcp6-change`, `dns-change`, `connectivity-change`
and `vpn-up`. `etc/init.d/bananarchy-time-sync` (`need chronyd net`,
`after networkmanager`) covers the boot race where dispatcher events fire
before chronyd is ready; both are backgrounded so they never block NM or
OpenRC.
- `/var/lib/chrony` is chowned to the `chrony` uid/gid in both
`rebuild-image.sh` and `apply-bananarchy-overlay.sh`, so the driftfile is
written and the frequency estimate survives reboots.
- `scripts/check-rebuild.sh` guards the four new files, the `iburst` /
`cmdport 0` pair, the runlevel hook and both ownership fixes.
### 16.3 Verification
On the live phone, `chronyc refresh` followed by `chronyc burst 2/4` over
`/run/chrony/chronyd.sock` resolved all four pool sources and stepped the
clock from `1970-01-12` to `Sat Nov 7 19:40:25 UTC 2026` within seconds;
`chronyc tracking` then showed `Reference ID : 53A84595
(hosted-by.SkillHost.PL)` and `System time : 0.000000000 seconds fast of NTP
time`. No UDP chronyc port was opened. The steady-state poll interval remains
`minpoll 12 maxpoll 16`, so U6's battery saving is preserved; the only extra
traffic is one short burst at boot and on each network transition.