diff --git a/packages/omamobile-device-husky/test/all b/packages/omamobile-device-husky/test/all index 55bc53d92..485275433 100755 --- a/packages/omamobile-device-husky/test/all +++ b/packages/omamobile-device-husky/test/all @@ -207,6 +207,16 @@ grep -qx 'supply=max77759-charger' "$tmp/root/usr/share/omamobile/charge-limit.c [[ ! -e $tmp/root/usr/lib/systemd/system/multi-user.target.wants/omamobile-charge-limit-apply.service ]] \ || fail "the apply unit is pulled in by udev, not enabled" pass "the charge limit declaration, its udev rule and the apply unit are staged; the unit is not enabled" +rule=vendor/udev/rules.d/75-omamobile-charge-limit.rules +unit=vendor/systemd/system/omamobile-charge-limit-apply.service +[[ $(grep -v '^#' "$rule" | grep -c .) -eq 1 ]] \ + && grep -qx 'SUBSYSTEM=="power_supply", KERNEL=="max77759-charger", TAG+="systemd", ENV{SYSTEMD_WANTS}+="omamobile-charge-limit-apply.service"' "$rule" \ + && ! grep -v '^#' "$rule" | grep -c ACTION >/dev/null \ + || fail "one rule, tag and SYSTEMD_WANTS on every event (Wants= is rebuilt per uevent)" +grep -qx 'RemainAfterExit=yes' "$unit" && grep -qx 'StopWhenUnneeded=yes' "$unit" \ + || fail "the apply unit stays active after its run (no restart per change event) and stops with the charger" +! grep -q '^StartLimitIntervalSec=0' "$unit" || fail "systemd's start limit stays on for the apply unit" +pass "the charge limit rule wants the unit on every event; the unit runs once per charger add" # --- the AoC start: hang marker, nothing without the node ------------------ diff --git a/packages/omamobile-device-husky/vendor/systemd/system/omamobile-charge-limit-apply.service b/packages/omamobile-device-husky/vendor/systemd/system/omamobile-charge-limit-apply.service index 9b68fd111..53afcf92d 100644 --- a/packages/omamobile-device-husky/vendor/systemd/system/omamobile-charge-limit-apply.service +++ b/packages/omamobile-device-husky/vendor/systemd/system/omamobile-charge-limit-apply.service @@ -2,14 +2,22 @@ # Applies the saved charge limit (/etc/omamobile/charge-limit) to the charger this package declares # (/usr/share/omamobile/charge-limit.conf). Pulled in by udev when the charger appears # (75-omamobile-charge-limit.rules); without a saved file the helper does nothing. The helper is omamobile-settings'. -# Not enabled. +# Not enabled. RemainAfterExit= keeps it active after one run, so the charger's change events (each one +# re-wants it) do not start it again (6968 starts in one boot on 2026-11-25 without it). StopWhenUnneeded= stops +# it when the charger device goes away (driver unbind or module reload), so the next add runs it again. A cable +# replug does not remove the device; the driver keeps the limit across it (checked 2026-11-25). +# On the 2026-11-27 boot systemd marked the charger active on its first change event, not the add, so +# that was the start. If that first run fails the unit is left failed, and the next change event wants it +# again: it is retried, within systemd's default start limit (5 starts in 10 s), not left failed until the +# next boot. (Read from systemd's behaviour and the 2026-11-25 count; a failing first run is not tested.) [Unit] Description=Apply the saved charge limit -StartLimitIntervalSec=0 After=local-fs.target ConditionFileIsExecutable=/usr/lib/omamobile-settings/charge-limit +StopWhenUnneeded=yes [Service] Type=oneshot +RemainAfterExit=yes ExecStart=/usr/lib/omamobile-settings/charge-limit TimeoutStartSec=15 diff --git a/packages/omamobile-device-husky/vendor/udev/rules.d/75-omamobile-charge-limit.rules b/packages/omamobile-device-husky/vendor/udev/rules.d/75-omamobile-charge-limit.rules index 2555686e8..5a6c1042f 100644 --- a/packages/omamobile-device-husky/vendor/udev/rules.d/75-omamobile-charge-limit.rules +++ b/packages/omamobile-device-husky/vendor/udev/rules.d/75-omamobile-charge-limit.rules @@ -2,6 +2,7 @@ # Apply the saved charge limit (/etc/omamobile/charge-limit) when the MAX77759 charger appears, at every boot, # through omamobile-charge-limit-apply.service rather than inside the udev worker. The helper acts only on the # supply this package declares in /usr/share/omamobile/charge-limit.conf; no saved file: nothing is touched. -# No ACTION filter: with ACTION=="add" the device loses its systemd tag on the charger's next change event, and -# the unit did not start at boot on husky (2026-11-16); without it, it does. +# No ACTION filter: systemd rebuilds a device's Wants= from SYSTEMD_WANTS on every uevent, so a rule on add +# only leaves Wants= empty after the charger's next change event. The unit keeps itself from storming on change +# events (RemainAfterExit=, StopWhenUnneeded=; see the unit). SUBSYSTEM=="power_supply", KERNEL=="max77759-charger", TAG+="systemd", ENV{SYSTEMD_WANTS}+="omamobile-charge-limit-apply.service" diff --git a/packages/omamobile-device-husky/version b/packages/omamobile-device-husky/version index 790629964..7e72641b4 100644 --- a/packages/omamobile-device-husky/version +++ b/packages/omamobile-device-husky/version @@ -1 +1 @@ -0.1.21 +0.1.22 diff --git a/packages/omamobile-settings/test/charge-backend.sh b/packages/omamobile-settings/test/charge-backend.sh index 4ba8f4e93..5990f76f2 100755 --- a/packages/omamobile-settings/test/charge-backend.sh +++ b/packages/omamobile-settings/test/charge-backend.sh @@ -106,7 +106,7 @@ if [[ -d $h ]]; then { echo "FAIL: udev: one rule, no ACTION filter, pulls in the apply unit" >&2; exit 1; } a=$h/vendor/systemd/system/omamobile-charge-limit-apply.service grep -qx 'ExecStart=/usr/lib/omamobile-settings/charge-limit' "$a" && grep -qx 'Type=oneshot' "$a" && - grep -qx 'StartLimitIntervalSec=0' "$a" && ! grep -q '^\[Install\]' "$a" || + grep -qx 'RemainAfterExit=yes' "$a" && ! grep -q '^\[Install\]' "$a" || { echo "FAIL: apply unit: oneshot helper with no argument, not enabled" >&2; exit 1; } grep -qx 'supply=max77759-charger' "$h/charge-limit.conf" || { echo "FAIL: husky declares max77759-charger" >&2; exit 1; } fi