From 608a8ac71b7d73d96f99d16ce62263192e5d83ec Mon Sep 17 00:00:00 2001 From: Luxferre Date: Sun, 8 Nov 2026 09:28:13 +0200 Subject: [PATCH] Replace idle network poller with event-driven dispatcher A/B measure and reject additional VM/sysctl/mount tweaks that did not improve idle without trade-offs. Remove sxmo_networkmonitor's long-lived nmcli device monitor, replace it with NetworkManager dispatcher hooks that run Sxmo network/statusbar hooks as the X session user, disable the superd unit in both start hooks, guard it in check-rebuild.sh, update docs, rebuild the image, and verify live Wi-Fi reconnect and idle context switches. --- AGENTS.md | 2 +- BATTERY-OPTIMIZATION-ANALYSIS.md | 92 +++++++++++++++++++ CHANGELOG.md | 36 ++++++++ MANUAL.md | 2 +- README.md | 2 +- .../30-bananarchy-network-status.sh | 14 +++ .../.config/sxmo/hooks/sxmo_hook_start.sh | 7 +- .../usr/bin/bananarchy-network-event.sh | 51 ++++++++++ .../sxmo/default_hooks/sxmo_hook_start.sh | 7 +- scripts/apply-bananarchy-overlay.sh | 4 + scripts/check-rebuild.sh | 26 ++++++ 11 files changed, 236 insertions(+), 7 deletions(-) create mode 100755 overlay/rootfs/etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh create mode 100755 overlay/rootfs/usr/bin/bananarchy-network-event.sh diff --git a/AGENTS.md b/AGENTS.md index 0ffef24..7d336f8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -76,7 +76,7 @@ Sync net time** (`src/sxmo-dmenu/dmenu.c` + `usr/bin/bananarchy-sync-net-time.sh`) forces the same burst manually and notifies the user, and the helper's `sync` mode reports the result. Keep DNS resolution outside the helper's `flock` so a long boot retry cannot swallow -network-up events, and keep `var/lib/chrony` owned by the `chrony` user. The status bar clock must be refreshed synchronously on unlock (`sxmo_hook_unlock.sh`) and by dmenu's `update_t9_status_indicator()` before `XStoreName()`; `sxmo_hook_statusbar.sh` forces a root-name refresh on `time` / `state_change`. `postmarketos-zram-swap` uses `/usr/bin/zramstart`, not `/etc/conf.d/zram-init`: keep `deviceinfo_zram_swap_algo="lz4"` in every `devices/*/deviceinfo*` file. Keep `vm.compaction_proactiveness=0` in `etc/sysctl.d/99-bananarchy-power.conf` and `etc/local.d/10-power-save.start`; see `BATTERY-OPTIMIZATION-ANALYSIS.md` §17. Deep standby is `bananarchy-suspend.sh` / `bananarchy-deep-standby.sh` / `sxmo_autosuspend.sh` / `sxmo_suspend.sh`, gated by `/etc/bananarchy-no-deep-standby` (shipped present = disabled) and inert because `CONFIG_SUSPEND` is off. A full custom module tree rebuild is deliberately **not** planned: this firmware has no PSCI `SYSTEM_SUSPEND`, so `CONFIG_SUSPEND` would only give s2idle (`freeze`), not `mem` / DDR self-refresh, for <1 mA of saving (see `BATTERY-OPTIMIZATION-ANALYSIS.md` §14 and §17). Never force `sxmo.noidle`/`sxmo.nosuspend` from the session scripts and never reintroduce the infinite `sxmo_not_suspendable` wakelock. `/etc/bananarchy/` is root-only. +network-up events, and keep `var/lib/chrony` owned by the `chrony` user. Network state changes are event-driven through `etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh` + `usr/bin/bananarchy-network-event.sh`; keep `superctl disable sxmo_networkmonitor` in the session start hooks, and never reintroduce `superctl start sxmo_networkmonitor` or a long-lived `nmcli device monitor`. The status bar clock must be refreshed synchronously on unlock (`sxmo_hook_unlock.sh`) and by dmenu's `update_t9_status_indicator()` before `XStoreName()`; `sxmo_hook_statusbar.sh` forces a root-name refresh on `time` / `state_change`. `postmarketos-zram-swap` uses `/usr/bin/zramstart`, not `/etc/conf.d/zram-init`: keep `deviceinfo_zram_swap_algo="lz4"` in every `devices/*/deviceinfo*` file. Keep `vm.compaction_proactiveness=0` in `etc/sysctl.d/99-bananarchy-power.conf` and `etc/local.d/10-power-save.start`; see `BATTERY-OPTIMIZATION-ANALYSIS.md` §17 and §18. Deep standby is `bananarchy-suspend.sh` / `bananarchy-deep-standby.sh` / `sxmo_autosuspend.sh` / `sxmo_suspend.sh`, gated by `/etc/bananarchy-no-deep-standby` (shipped present = disabled) and inert because `CONFIG_SUSPEND` is off. A full custom module tree rebuild is deliberately **not** planned: this firmware has no PSCI `SYSTEM_SUSPEND`, so `CONFIG_SUSPEND` would only give s2idle (`freeze`), not `mem` / DDR self-refresh, for <1 mA of saving (see `BATTERY-OPTIMIZATION-ANALYSIS.md` §14 and §17). Never force `sxmo.noidle`/`sxmo.nosuspend` from the session scripts and never reintroduce the infinite `sxmo_not_suspendable` wakelock. `/etc/bananarchy/` is root-only. - **Image residue**: `rebuild-image.sh` strips `/var/cache/apk`, all `apk.log*` files, and unused gettext locale trees before `mke2fs` and aborts the build if any apk cache/log remains; never add an `apk` call after that guard. - **No on-device compiler**: `scripts/rootfs-packages.txt` ships no `gcc`/`g++`/`musl-dev`/`make` and no Janet runtime (`janet`, `janet-dev`, `jpm`); cross-compile native code with `scripts/build-*.sh`. On-device development uses the Yabasic FFI SDK (`neoui.yab` / `neonet.yab`), which requires `yabasic`, `libffi`, `libneoui.so`, and `libcurl.so.4` — never remove those. `scripts/check-rebuild.sh` guards both sides. - **Core tools**: `curl`, `bc`, `ed`, `rlwrap`, `mandoc`, `nano`, `less`, and `frotz` are pinned core tools asserted by `scripts/check-rebuild.sh`. Perl, Lua, optional Tcl extensions, and the `sqlite` CLI are excluded, while `tcl`, `python3`, `bash`, `luajit`, `gawk`, `jq`, `gojq`, and `quickjs` remain as hard runtime dependencies. diff --git a/BATTERY-OPTIMIZATION-ANALYSIS.md b/BATTERY-OPTIMIZATION-ANALYSIS.md index 5c26e7d..967c11f 100644 --- a/BATTERY-OPTIMIZATION-ANALYSIS.md +++ b/BATTERY-OPTIMIZATION-ANALYSIS.md @@ -1038,3 +1038,95 @@ The AP and userspace are already close to their idle floor. Further 24 h battery life has to come from modem/Wi-Fi RF policy, DDR self-refresh, or a battery-powered measurement campaign; another kernel config trim or full module tree rebuild is not justified. + +--- + +## 18. No-tradeoff idle headroom: A/B sweep and event-driven process cleanup + +This section answers a narrower question than section 17: what can still be +saved at idle **without** delaying UI wakeup, calls/SMS, Wi-Fi, or network +state changes? All measurements below were 45-60 s screen-off windows on the +same USB-charged phone, so they are wakeup/IRQ/context-switch counts rather +than discharge mA. `vm.compaction_proactiveness=0` from section 17 stayed +active throughout. + +### 18.1 Kernel/VFS candidates that were measured and rejected + +| Candidate | Baseline | Candidate result | Decision | +| --- | --- | --- | --- | +| `vm.stat_interval=120` (from 30) | 96.85% CPU idle, 30.07 timer IRQs/s | 96.10% idle, 36.38 timer IRQs/s, `mmc0` 0.89/s | Rejected; worse or noise | +| `vm.vfs_cache_pressure=50` (from 150) | 96.85% idle | 94.34% idle, 47.38 timer IRQs/s | Rejected | +| `vm.swappiness=100` (from 180) | 96.85% idle, `mmc0` 0.21/s | 96.47% idle, `mmc0` 1.69/s | Rejected | +| `kernel.sched_autogroup_enabled=0` | 96.85% idle | 95.46% idle, 37.50 timer IRQs/s | Rejected | +| `noatime` rootfs remount | first run 96.85% -> 97.38% idle | confirmation run 97.49% -> 95.90% idle | Rejected; contradictory A/B | + +`kernel.timer_migration` was already `1`. `vm.page-cluster=0`, +`vm.dirty_writeback_centisecs=6000`, `vm.dirty_expire_centisecs=6000`, +`kernel.nmi_watchdog=0`, `workqueue.power_efficient=Y` and the SPI/GPU/CPU +runtime-PM settings from earlier sections were already active. Raising the +dirty writeback interval or adding `commit=` would risk data loss on a sudden +power cut, so neither was shipped. All rejected sysctls and `relatime` were +restored on the live phone. + +### 18.2 Process management: remove the `nmcli device monitor` poller + +`sxmo_networkmonitor.sh` kept a long-lived `nmcli device monitor` plus two +shell wrappers alive to translate NetworkManager device states into Sxmo +network hooks and status bar updates. It accounted for roughly 0.08-0.13 +context switches/s and duplicated the dispatcher path already used for DPM +and time sync. + +It is replaced by: + +- `etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh`, which + reacts to `up`, `down`, `pre-up`, `pre-down`, VPN equivalents, and + connectivity/DHCP/DNS changes, then double-forks so NetworkManager never + waits for shell hooks. +- `usr/bin/bananarchy-network-event.sh`, re-executed as the X session user + via `su`, which resolves the device type and calls the same + `sxmo_hook_network_{up,down,pre_up,pre_down}.sh` and + `sxmo_hook_statusbar.sh network` hooks. Running as the user keeps + `sxmo_status` files, the root status name and the status bar cache + user-owned. +- Both `sxmo_hook_start.sh` copies now run + `superctl disable sxmo_networkmonitor` instead of starting the poller; + `scripts/check-rebuild.sh` guards this. + +This does not stop NetworkManager, wpa_supplicant, dnsmasq, ModemManager, +rmtfs, q6voiced, the DSDS helper, chronyd, dunst, or any preloaded DWM plugin. +Incoming network events still wake the same hooks immediately; only the idle +poller and its two shell wrappers disappear. Live verification after a Wi-Fi +disconnect/reconnect logged `09:22:55 up wlan0 wifi` from a temporary user +`sxmo_hook_network_up.sh`, with `wlan0` back on `OffOurStreets_`, +`sxmo_networkmonitor` stopped, `network_monitor_device` gone and no +`nmcli device monitor` process. A 60 s screen-off window after the change +measured 97.78% CPU idle with no `nmcli device monitor` in the top context +switchers (it had been ~0.08-0.13/s before). + +### 18.3 Still available, but deliberately not shipped + +- **Longer `statusbar_periodics` interval**: 300 s could become 600 s because + dmenu and unlock now refresh the clock, but an on-screen idle clock could + then be up to 10 minutes stale. Not shipped. +- **Longer `dsds-daemon` / `sxmo_modemmonitor.sh` / Wi-Fi scan intervals**: + these would delay modem or roaming state changes. Not shipped. +- **Consolidating `sxmo_soundmonitor.sh` / `sxmo_modemmonitor.sh` shell + pipelines**: possible, but they are event-driven (`evtest`, + `pactl subscribe`, `dbus-monitor`) and rewriting them risks audio/call + routing regressions for sub-0.1/s savings. Not shipped. +- **Wi-Fi listen interval >5, `MODEM_DRX_MODE=6-9`, `DSDS_SECONDARY_MODE=eco`**: + these trade inbound latency or SIM2 reachability for RF saving, so they + stay opt-in via `/etc/bananarchy-power-policy.conf`. +- **Serial console removal, `commit=60`, ABI-breaking kernel configs, full + module tree rebuild**: rejected for the reasons in sections 14-17. + +### 18.4 Verdict + +After sections 17 and 18, the remaining no-tradeoff AP/userspace headroom is +very small: the kernel is already ~98-99% idle, the 26 preloaded plugins and +Xorg are asleep when dark, runtime PM has collapsed the GPU/SDHCI/SPI/DMA +domains, and the remaining periodic work is either event-driven or spaced +300-1800 s apart. Further meaningful 24 h gains still require radio firmware +policy, DDR self-refresh via lk2nd PSCI `SYSTEM_SUSPEND`, or a real +battery-powered discharge measurement; they cannot come from more idle +timer/sysctl trimming without hurting latency or connectivity. diff --git a/CHANGELOG.md b/CHANGELOG.md index bd48dc9..dc6da09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,42 @@ Release versions follow the `
` format (where `2026` is `a`, --- +## Unreleased — event-driven network status and no-tradeoff idle A/B sweep + +- **Removed the `nmcli device monitor` poller**: `sxmo_networkmonitor.sh` + kept a long-lived NetworkManager device monitor plus two shell wrappers + alive to drive Sxmo network hooks and the status bar. It is replaced by + `etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh` and + `usr/bin/bananarchy-network-event.sh`. The dispatcher reacts to `up`, + `down`, `pre-up`, `pre-down`, VPN, connectivity, DHCP and DNS events and + double-forks so NetworkManager is never blocked; the helper runs as the X + session user so `sxmo_status` files stay user-owned. Both + `sxmo_hook_start.sh` copies now disable the `sxmo_networkmonitor` superd + unit instead of starting it, and `scripts/check-rebuild.sh` guards the + replacement. NetworkManager, + wpa_supplicant, dnsmasq, ModemManager and all call/SMS daemons are untouched. + Live verification: a Wi-Fi reconnect invoked the user network-up hook, + `sxmo_networkmonitor` / `network_monitor_device` / `nmcli device monitor` + are gone, and a 60 s screen-off window measured 97.78% CPU idle with no + monitor poller in the top context switchers. +- **A/B measured and rejected further kernel/VFS tweaks**: 45-60 s screen-off + windows showed no consistent win from `vm.stat_interval=120`, + `vm.vfs_cache_pressure=50`, `vm.swappiness=100`, + `kernel.sched_autogroup_enabled=0` or a `noatime` rootfs remount; several + made CPU idle and timer IRQs worse. `kernel.timer_migration` was already + `1`. All rejected sysctls and `relatime` were restored. `commit=` and longer + dirty writeback were not shipped because they risk data loss on sudden power + cut. +- `BATTERY-OPTIMIZATION-ANALYSIS.md` section 18 records the full A/B table, + the event-driven process change, and the remaining opportunities that were + deliberately not shipped because they would delay Wi-Fi/modem state, + inbound data, SIM2 reachability, or the on-screen clock. +- `scripts/apply-bananarchy-overlay.sh` installs the new helper and dispatcher + script root-owned and executable; `AGENTS.md`, `MANUAL.md` and `README.md` + were synchronized. Image and live phone were redeployed and verified. + +--- + ## Unreleased — xkopher focus scrolling, fresh unlock clock, battery longevity re-analysis - **xkopher link focus visibility**: `smallweb_plugin.cpp` now builds display diff --git a/MANUAL.md b/MANUAL.md index c986de4..857065e 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -23,7 +23,7 @@ This manual covers flashing, operating, and customizing **Bananarchy Linux** (`2 ### 1.3 Core architecture highlights 1. **Pure X11 (`Xlibre` + `sxmo-de-dwm`) for `240x320` QVGA displays**: - Uses a lightweight cross-compiled **Xlibre** server with `modesetting` KMS, partial-rectangle `ShadowFB` SPI updates, and zero Wayland overhead. - - **Patched `dwm`** provides a `240x320` vertical bottom-stack (`bstack`) layout, a 24px top status bar, a transparent `"Menu"` / `"Names"` desktop softkey bar, a native `ParentRelative` desktop datetime overlay (`Fira Code` 32pt `%H:%M` and 14pt `%a %d %b %Y` with 1px drop shadow, rendered directly by `dwm` with zero external Conky process overhead and automatic live timezone/wallpaper refresh), and `< 2 ms` handling of physical slider (`SW_LID`) and wake keys. The status bar clock is refreshed synchronously on unlock and whenever dmenu updates its input-method indicator, so it cannot keep showing a pre-lock time after the panel wakes. + - **Patched `dwm`** provides a `240x320` vertical bottom-stack (`bstack`) layout, a 24px top status bar, a transparent `"Menu"` / `"Names"` desktop softkey bar, a native `ParentRelative` desktop datetime overlay (`Fira Code` 32pt `%H:%M` and 14pt `%a %d %b %Y` with 1px drop shadow, rendered directly by `dwm` with zero external Conky process overhead and automatic live timezone/wallpaper refresh), and `< 2 ms` handling of physical slider (`SW_LID`) and wake keys. The status bar clock is refreshed synchronously on unlock and whenever dmenu updates its input-method indicator, so it cannot keep showing a pre-lock time after the panel wakes. Network state changes are handled by the NetworkManager dispatcher instead of a long-lived `nmcli device monitor`, so connectivity stays immediate without an idle poller. 2. **Preloaded resident DWM plugins (`< 2 ms` wakeup)**: - Core phone applications (`dmenu`, `xdrawer`, `dialer`, `calllog`, `callscreen`, `contacts`, `sms`, `files`, `camera`, `themes`, `passcode`, `modem`, `networks`, `ringtones`, `wallpapers`, `music`, `sip`, `email`, `irc`, `tox`, `smallweb`, `webarchy`, `gps`, `privacy`, `engmenu`, `locker`) run as preloaded resident daemons (`dwm-plugin --preload`) that sleep at 0% CPU and open instantaneously over FIFO/socket IPC. - All UI elements — including the `dunst` notification daemon (`bananarchy-sync-dunst-theme`) — share the **NeoUI SDK (`libneoui.so` + `/usr/include/neoui.h`)** and a single **XRDB theming engine** (`~/.xthemes/*.xth` -> `~/.Xresources`) with 21 preinstalled color schemes, proportional font sizing (`theme.baseFontSize`), and live reload without restarting X11. NeoUI exposes both C++20 classes and a C-compatible FFI (`neoui_*`) for building custom native or scripted (`yabasic` via `~/Projects/neoui.yab`, `~/Projects/neoui_demo.yab`, and `~/Projects/bulls_cows.yab`, paired with **NeoNet** in `~/Projects/neonet.yab` and `~/Projects/neonet_demo.yab` for `libcurl` HTTP/HTTPS and TCP/TLS/UDP socket networking) `240x320` GUI applications — see [SDK.md](./SDK.md) for the complete API reference and examples. diff --git a/README.md b/README.md index 291c433..0fc7434 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ## Key features ### System and hardware support -- **Mainline Linux 6.12 kernel**: custom patches and out-of-tree drivers for Qualcomm **Adreno 304 (`FD304`, 96 KB GMEM)** 3D GPU acceleration (`drm/msm` + `qcom-iommu`), Qualcomm QDSP6/Q6Voice audio routing, Dual-SIM modem control, the rear 2MP GalaxyCore `GC2395` / `GC2385` / `GC2365` camera (`/dev/video0`), the `SY7807` flashlight LED (`white:torch`), physical keypad/slider events, and clean PM8909 poweroff. The kernel image is built from `config-bananarchy-msm8909.armv7` with the known-good pmaports module ABI, and ships with idle-blanking power management; `BATTERY-OPTIMIZATION-ANALYSIS.md` records the measured idle state and explains why suspend-to-RAM is unavailable on this firmware (PSCI `SYSTEM_SUSPEND` missing) and why a full custom module tree rebuild is not worthwhile. Section 17 adds a post-`a1107` re-analysis and two low-risk wins: the active zram swap now uses `lz4` instead of `zramstart`'s `zstd` default, and `vm.compaction_proactiveness=0` removes ~2 `kcompactd0` wakeups/s. Runtime Wi-Fi listen-interval, modem DRX and DSDS secondary-SIM power policies are configurable in `/etc/bananarchy-power-policy.conf`; see `MANUAL.md`. +- **Mainline Linux 6.12 kernel**: custom patches and out-of-tree drivers for Qualcomm **Adreno 304 (`FD304`, 96 KB GMEM)** 3D GPU acceleration (`drm/msm` + `qcom-iommu`), Qualcomm QDSP6/Q6Voice audio routing, Dual-SIM modem control, the rear 2MP GalaxyCore `GC2395` / `GC2385` / `GC2365` camera (`/dev/video0`), the `SY7807` flashlight LED (`white:torch`), physical keypad/slider events, and clean PM8909 poweroff. The kernel image is built from `config-bananarchy-msm8909.armv7` with the known-good pmaports module ABI, and ships with idle-blanking power management; `BATTERY-OPTIMIZATION-ANALYSIS.md` records the measured idle state and explains why suspend-to-RAM is unavailable on this firmware (PSCI `SYSTEM_SUSPEND` missing) and why a full custom module tree rebuild is not worthwhile. Section 17 adds a post-`a1107` re-analysis and two low-risk wins: the active zram swap now uses `lz4` instead of `zramstart`'s `zstd` default, and `vm.compaction_proactiveness=0` removes ~2 `kcompactd0` wakeups/s. Section 18 replaces the idle `nmcli device monitor` poller with NetworkManager dispatcher hooks and records the kernel/VFS tweaks that were A/B tested and rejected. Runtime Wi-Fi listen-interval, modem DRX and DSDS secondary-SIM power policies are configurable in `/etc/bananarchy-power-policy.conf`; see `MANUAL.md`. - **Alpine Linux Edge base**: full access to the Alpine package ecosystem with `< 95 MB` idle RAM usage on 512 MB devices and full local root access out of the box. - **Network time synchronisation**: `chronyd` uses `iburst` with long `minpoll 12 maxpoll 16` polls; `bananarchy-time-sync.sh` re-resolves the NTP pool and requests an immediate burst over chronyd's root-only Unix socket when NetworkManager brings a connection up, so the clock is set within seconds of boot or a Wi-Fi reconnect without shortening the battery-friendly steady-state interval. **Config -> Sync net time** forces a burst manually and reports the result when autosync is slow. The status bar clock is also refreshed synchronously on unlock and by dmenu itself, so it cannot show a stale pre-lock time. See `MANUAL.md` section 5.7. - **Pure X11 graphical stack with GPU acceleration**: cross-compiled **Xlibre** (`X11Libre/xserver`) display server offloading 2D/3D screen rendering to the **Adreno 304 GPU** via **Glamor, DRI3, GLX, and Mesa Freedreno (`FD304`, OpenGL 3.1 / OpenGL ES 3.0)** over `panel-mipi-dbi` KMSRO, paired with a customized **Sxmo (`sxmo-de-dwm`)** window manager (`240x320` vertical stack layout, native `ParentRelative` desktop clock and softkey bar without Conky overhead, `< 2 ms` slider/key wake latency, and zero Wayland overhead). diff --git a/overlay/rootfs/etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh b/overlay/rootfs/etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh new file mode 100755 index 0000000..3bee615 --- /dev/null +++ b/overlay/rootfs/etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# NetworkManager dispatcher: replace sxmo_networkmonitor's long-lived +# "nmcli device monitor" with event-driven Sxmo network/statusbar hooks. +# The helper re-executes as the X session user so status files stay owned by +# user:user. Double-fork so NetworkManager never waits for shell hooks. +case "${2:-}" in + up|down|pre-up|pre-down|vpn-up|vpn-down|vpn-pre-up|vpn-pre-down|\ + connectivity-change|dhcp4-change|dhcp6-change|dns-change) ;; + *) exit 0 ;; +esac +( su user -s /bin/sh -c \ + "/usr/bin/bananarchy-network-event.sh '$1' '$2'" \ + >/dev/null 2>&1 & ) 2>/dev/null || true +exit 0 diff --git a/overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh b/overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh index 5b95204..11df708 100755 --- a/overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh +++ b/overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh @@ -113,8 +113,11 @@ if [ -z "$SXMO_NO_MODEM" ] && command -v ModemManager > /dev/null; then sxmo_wakelock.sh lock sxmo_modem_warming_up 120s fi -# It watch network changes and update the status bar icon by example -superctl start sxmo_networkmonitor +# Network state changes are handled by the NetworkManager dispatcher +# (30-bananarchy-network-status.sh + bananarchy-network-event.sh), so no +# long-lived "nmcli device monitor" poller is started at idle. Disable the +# superd unit too, in case an older session enabled it. +superctl disable sxmo_networkmonitor >/dev/null 2>&1 || true # The daemon that display notifications popup messages superctl start sxmo_notificationmonitor diff --git a/overlay/rootfs/usr/bin/bananarchy-network-event.sh b/overlay/rootfs/usr/bin/bananarchy-network-event.sh new file mode 100755 index 0000000..091fa03 --- /dev/null +++ b/overlay/rootfs/usr/bin/bananarchy-network-event.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# NetworkManager dispatcher helper: run Sxmo network hooks as the X session +# user. The dispatcher runs as root; keeping status files user-owned avoids +# breaking sxmo_status.sh, dmenu and the status bar after a network event. +set -u + +DEVICE="${1:-}" +ACTION="${2:-}" +[ -n "$DEVICE" ] && [ -n "$ACTION" ] || exit 0 + +export HOME=/home/user +export USER=user +export LOGNAME=user +export SHELL=/bin/ash +export XDG_RUNTIME_DIR=/run/user/10000 +export XDG_CONFIG_HOME=/home/user/.config +export XDG_CACHE_HOME=/home/user/.cache +export XDG_DATA_HOME=/home/user/.local/share +export XDG_STATE_HOME=/home/user/.local/state +export SXMO_WM=dwm +export SXMO_STATE=/run/user/10000/sxmo.state +export SXMO_STATUS_NAME=default +export DISPLAY=:0 +export PATH="/home/user/.local/bin:/home/user/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin" + +TYPE="$(nmcli -g GENERAL.TYPE device show "$DEVICE" 2>/dev/null || true)" +[ -n "$TYPE" ] || TYPE=unknown + +case "$ACTION" in + up|vpn-up) + sxmo_hook_network_up.sh "$DEVICE" "$TYPE" >/dev/null 2>&1 || true + sxmo_hook_statusbar.sh network "$TYPE" "$DEVICE" >/dev/null 2>&1 || true + ;; + down|vpn-down) + sxmo_hook_network_down.sh "$DEVICE" "$TYPE" >/dev/null 2>&1 || true + sxmo_hook_statusbar.sh network "$TYPE" "$DEVICE" >/dev/null 2>&1 || true + ;; + pre-up|vpn-pre-up) + sxmo_hook_network_pre_up.sh "$DEVICE" "$TYPE" >/dev/null 2>&1 || true + sxmo_hook_statusbar.sh network "$TYPE" "$DEVICE" >/dev/null 2>&1 || true + ;; + pre-down|vpn-pre-down) + sxmo_hook_network_pre_down.sh "$DEVICE" "$TYPE" >/dev/null 2>&1 || true + sxmo_hook_statusbar.sh network "$TYPE" "$DEVICE" >/dev/null 2>&1 || true + ;; + connectivity-change|dhcp4-change|dhcp6-change|dns-change) + sxmo_hook_statusbar.sh network "$TYPE" "$DEVICE" >/dev/null 2>&1 || true + ;; + *) exit 0 ;; +esac +exit 0 diff --git a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_start.sh b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_start.sh index eb5f706..1c6062b 100755 --- a/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_start.sh +++ b/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_start.sh @@ -121,8 +121,11 @@ if [ -z "$SXMO_NO_MODEM" ] && command -v ModemManager > /dev/null; then sxmo_wakelock.sh lock sxmo_modem_warming_up 120s fi -# It watch network changes and update the status bar icon by example -superctl start sxmo_networkmonitor +# Network state changes are handled by the NetworkManager dispatcher +# (30-bananarchy-network-status.sh + bananarchy-network-event.sh), so no +# long-lived "nmcli device monitor" poller is started at idle. Disable the +# superd unit too, in case an older session enabled it. +superctl disable sxmo_networkmonitor >/dev/null 2>&1 || true # The daemon that display notifications popup messages superctl start sxmo_notificationmonitor diff --git a/scripts/apply-bananarchy-overlay.sh b/scripts/apply-bananarchy-overlay.sh index 4623601..c9bfcd1 100755 --- a/scripts/apply-bananarchy-overlay.sh +++ b/scripts/apply-bananarchy-overlay.sh @@ -116,14 +116,18 @@ chmod 640 "$TARGET_ROOTFS/etc/doas.d/50-sxmo.conf" 2>/dev/null || true chown 0:0 "$TARGET_ROOTFS/etc/chrony/chrony.conf" \ "$TARGET_ROOTFS/usr/bin/bananarchy-time-sync.sh" \ "$TARGET_ROOTFS/usr/bin/bananarchy-sync-net-time.sh" \ + "$TARGET_ROOTFS/usr/bin/bananarchy-network-event.sh" \ "$TARGET_ROOTFS/etc/init.d/bananarchy-time-sync" \ "$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/20-bananarchy-time-sync.sh" \ + "$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh" \ 2>/dev/null || true chmod 0644 "$TARGET_ROOTFS/etc/chrony/chrony.conf" 2>/dev/null || true chmod 0755 "$TARGET_ROOTFS/usr/bin/bananarchy-time-sync.sh" \ "$TARGET_ROOTFS/usr/bin/bananarchy-sync-net-time.sh" \ + "$TARGET_ROOTFS/usr/bin/bananarchy-network-event.sh" \ "$TARGET_ROOTFS/etc/init.d/bananarchy-time-sync" \ "$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/20-bananarchy-time-sync.sh" \ + "$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh" \ 2>/dev/null || true CHRONY_UID="$(awk -F: '/^chrony:/ {print $3}' "$TARGET_ROOTFS/etc/passwd" 2>/dev/null || true)" CHRONY_GID="$(awk -F: '/^chrony:/ {print $4}' "$TARGET_ROOTFS/etc/passwd" 2>/dev/null || true)" diff --git a/scripts/check-rebuild.sh b/scripts/check-rebuild.sh index cc376fd..4024535 100755 --- a/scripts/check-rebuild.sh +++ b/scripts/check-rebuild.sh @@ -254,6 +254,32 @@ for f in "$UNLOCK_HOOK" "$STATUS_HOOK"; do fi done +echo "[check] Event-driven network status..." +NET_EVENT="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-network-event.sh" +NET_DISPATCH="$BASE_DIR/overlay/rootfs/etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh" +for f in "$NET_EVENT" "$NET_DISPATCH"; do + if [ ! -f "$f" ]; then + fail "missing ${f#$BASE_DIR/}" + elif ! sh -n "$f" 2>/dev/null; then + fail "shell syntax: ${f#$BASE_DIR/}" + fi +done +for hook in "$BASE_DIR/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_start.sh" \ + "$BASE_DIR/overlay/rootfs/etc/skel/.config/sxmo/hooks/sxmo_hook_start.sh"; do + if grep -q 'superctl start sxmo_networkmonitor' "$hook"; then + fail "${hook#$BASE_DIR/} still starts the nmcli device monitor poller" + fi + if ! grep -q '30-bananarchy-network-status.sh' "$hook"; then + fail "${hook#$BASE_DIR/} no longer documents the dispatcher replacement" + fi + if ! grep -q 'superctl disable sxmo_networkmonitor' "$hook"; then + fail "${hook#$BASE_DIR/} no longer disables the sxmo_networkmonitor superd unit" + fi +done +if ! grep -q 'bananarchy-network-event.sh' "$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then + fail "apply-bananarchy-overlay.sh no longer installs the network event helper" +fi + echo "[check] Battery longevity settings..." for f in "$BASE_DIR"/devices/*/deviceinfo "$BASE_DIR"/devices/*/deviceinfo.nokia-leo; do [ -f "$f" ] || continue