From 9d12dedb8666ced17fa4cdeaa55b04e16dce10c6 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 9 Nov 2026 19:41:35 -0500 Subject: [PATCH 1/2] power-ab: the sleep preflight reads the charge, not just tests for the file The --suspend preflight accepted a gauge whose charge_counter or charge_now file was readable. A gauge that withholds its charge has readable files and no figure: with linux-omarchy-mobile#234 the 9a's MAX77779 answers ENODATA for charge_now while its power-on-reset bit is set, so the run would start and its sleep phase, whose only number is the charge difference, would record nothing. The preflight now reads one of the two and refuses when neither gives a value. Checked with two stand-in directories: a file holding a number passes; a file that exists but fails to read is refused, where the old -r test passed it. Co-Authored-By: Claude Fable 5.2 --- tools/power-ab | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/power-ab b/tools/power-ab index 7fff87a67..7de0bd441 100755 --- a/tools/power-ab +++ b/tools/power-ab @@ -124,8 +124,11 @@ case "$test" in { echo "power-ab: systemctl suspend would not enter s2idle here" >&2; exit 1; } ;; *) echo "power-ab: --suspend takes rtcwake or systemd, not '$suspend'" >&2; exit 1 ;; esac - [[ -r "$bat/charge_counter" || -r "$bat/charge_now" ]] \ - || { echo "power-ab: the gauge has neither charge_counter nor charge_now" >&2; exit 1; } ;; + # Read one, not just test for the file: a gauge that withholds its charge + # (the 9a's MAX77779 after a power-on reset answers ENODATA) has readable + # files and no figure, and the sleep phase's only number comes from them + cat "$bat/charge_counter" >/dev/null 2>&1 || cat "$bat/charge_now" >/dev/null 2>&1 \ + || { echo "power-ab: the gauge gives neither charge_counter nor charge_now (a file that can't be read, or no data after a gauge reset)" >&2; exit 1; } ;; units) [[ -n "$units$user_units" ]] || { echo "power-ab: units needs --units or --user-units" >&2; exit 1; } ;; eas) From e3572c6bbf66664c84730ff32fbcdb572325b3e1 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Tue, 10 Nov 2026 08:09:21 -0500 Subject: [PATCH 2/2] power-ab: check before detaching, so a refusal is seen With --detach the script re-ran itself in the background before any of its checks, with its output sent nowhere. A refusal (no battery, no s2idle, a gauge that withholds its charge) then happened in the detached copy: the caller read "started; unplug within 60 s", unplugged, and nothing ran. The checks now run first, in the caller's terminal, and the detached copy runs them again. Co-Authored-By: Claude Fable 5.2 --- tools/power-ab | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/power-ab b/tools/power-ab index 7de0bd441..a2e272c3c 100755 --- a/tools/power-ab +++ b/tools/power-ab @@ -85,14 +85,6 @@ done [[ -n "$test" ]] || usage 1 [[ $EUID -eq 0 ]] || { echo "power-ab: run as root" >&2; exit 1; } -if ((detach)); then - args=(--unplug "$unplug" --phase "$phase" --settle "$settle" --rounds "$rounds" --delay-ms "$delay_ms" - --units "$units" --user-units "$user_units" --user "$uname" --suspend "$suspend" "$test") - setsid nohup "$0" "${args[@]}" > /dev/null 2>&1 < /dev/null & - echo "power-ab: started (pid $!); unplug within ${unplug} s" - exit 0 -fi - # The battery: the power supply of type Battery that reports current_now bat= for d in /sys/class/power_supply/*; do @@ -143,6 +135,16 @@ case "$test" in || { echo "power-ab: no CPU energy model in /sys/kernel/debug/energy_model: EAS can't engage" >&2; exit 1; } ;; esac +# Detach only after the checks above: a detached run has no terminal, so a +# refusal there would go nowhere and the owner would unplug for nothing +if ((detach)); then + args=(--unplug "$unplug" --phase "$phase" --settle "$settle" --rounds "$rounds" --delay-ms "$delay_ms" + --units "$units" --user-units "$user_units" --user "$uname" --suspend "$suspend" "$test") + setsid nohup "$0" "${args[@]}" > /dev/null 2>&1 < /dev/null & + echo "power-ab: started (pid $!); unplug within ${unplug} s" + exit 0 +fi + # The units test touches only units that are active now [[ -z "$uname" ]] && uname=$(loginctl list-users --no-legend 2>/dev/null | awk '$2 != "root" {print $2; exit}') usys=() uusr=()