From da6e36d6d560d41b48c3fe33fde31a322e7f0294 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Wed, 18 Nov 2026 10:29:51 -0649 Subject: [PATCH 1/4] omamobile-gnss 0.2.12: a location request before gnssd is up waits for it on the Pixel 9a The 9a's gnssd starts some 20 s after the modem is ONLINE (OMAMOBILE_MODEM_GNSS_DELAY). A location request in that window found no @GNSSND, and omamobile-gnss-start exited at once with "nothing to do". GeoClue reconnected at once, so the unit started five times in a second; systemd's start limit then failed it, and omamobile-gnss-nmea.socket with it, for the rest of the boot. GeoClue answered "Connection refused" every 5 s and Location stayed dead until it was switched off and on (#864, the first request after a boot). Now, when the modem unit is up or starting with OMAMOBILE_MODEM_GNSS=1, the start waits for gnssd, 90 s at most, and goes on as soon as it listens. Where gnssd won't come (the modem off, or started without GNSS), the start still says "nothing to do", but holds the client's connection 5 s first, so a client that reconnects at once can't run the unit into the start limit. Tested: test/all gains four cases with a stand-in systemctl: no gnssd and none coming gives up after the hold; a modem without GNSS doesn't wait; a modem bringing gnssd that never comes gives up after the wait; gnssd appearing during the wait starts gnss-slsi. On a Pixel 9a after a clean reboot, a where-am-i request at 5 s of uptime, before the modem unit had started: the start logged the wait at 14 s, went on at 37 s as gnssd listened, and the first position came at 63 s, with no off and on and nothing at the start limit. --- .../omamobile-gnss/lib/omamobile-gnss-start | 28 ++++++++++++++- packages/omamobile-gnss/test/all | 36 +++++++++++++++++++ packages/omamobile-gnss/version | 2 +- 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/packages/omamobile-gnss/lib/omamobile-gnss-start b/packages/omamobile-gnss/lib/omamobile-gnss-start index ae2df29eb..c4ef468b6 100755 --- a/packages/omamobile-gnss/lib/omamobile-gnss-start +++ b/packages/omamobile-gnss/lib/omamobile-gnss-start @@ -16,6 +16,24 @@ SESSION=/run/omamobile-gnss/session STOP_REQUEST=/run/omamobile-gnss/stop-request say() { printf 'omamobile-gnss: %s\n' "$*" >&2; } +# The 9a's gnssd: up when its socket is listening. The modem profile starts it +# some 20 s after the CP is ONLINE (OMAMOBILE_MODEM_GNSS_DELAY), when the +# modem unit runs with OMAMOBILE_MODEM_GNSS=1; a location request in that +# window waits for it (GNSSD_WAIT s at most) rather than finding nothing. +GNSSD_WAIT=${OMAMOBILE_GNSS_GNSSD_WAIT:-90} +# Without gnssd the start holds the client's connection this long before it +# exits: a client that reconnects at once (GeoClue) would otherwise start the +# unit five times in a second, and systemd's start limit would fail it and +# its socket for the rest of the boot. +NOTHING_HOLD=${OMAMOBILE_GNSS_NOTHING_HOLD:-5} +gnssd_up() { grep -c '@GNSSND' /proc/net/unix >/dev/null; } +gnssd_coming() { + local state env + state=$(${OMAMOBILE_GNSS_SYSTEMCTL:-systemctl} show -p ActiveState --value omamobile-tegu-modem.service 2>/dev/null) || return 1 + env=$(${OMAMOBILE_GNSS_SYSTEMCTL:-systemctl} show -p Environment --value omamobile-tegu-modem.service 2>/dev/null) || return 1 + [[ $state == active || $state == activating ]] && [[ " $env " == *" OMAMOBILE_MODEM_GNSS=1 "* ]] +} + # the Pixel 9a (zumapro-tegu) runs the gnss-slsi profile, the Pixel 7 Pro gnss # OMAMOBILE_DT lets the tests run both branches on any machine (as # omamobile-setup-user does). @@ -71,8 +89,16 @@ fi # the modem profile, and the gnss-slsi profile runs the HAL and our client, # which writes NMEA to the FIFO the bridge reads. Nothing to load here. if tegu; then - if ! grep -c '@GNSSND' /proc/net/unix >/dev/null; then + if ! gnssd_up && gnssd_coming; then + say "waiting for gnssd: the modem profile starts it some 20 s after the modem is ONLINE" + for ((i = 0; i < GNSSD_WAIT; i++)); do + gnssd_up && break + sleep 1 + done + fi + if ! gnssd_up; then say "gnssd isn't running (the modem profile with OMAMOBILE_MODEM_GNSS=1); nothing to do" + sleep "$NOTHING_HOLD" exit 0 fi # The HAL client is in the package only when it was built with diff --git a/packages/omamobile-gnss/test/all b/packages/omamobile-gnss/test/all index 006c3afa7..8dba39652 100755 --- a/packages/omamobile-gnss/test/all +++ b/packages/omamobile-gnss/test/all @@ -92,6 +92,42 @@ grep -c 'gnss-slsi start' "$tmp/log" >/dev/null && fail "9a branch: a start with run_start "$tmp/dt" "$tmp/unix" grep -c 'gnss-slsi' "$tmp/log" >/dev/null && fail "7 Pro branch: must not touch gnss-slsi" [[ ! -e "$tmp/var/lib/omamobile/gnss-bringup-started" ]] || fail "7 Pro branch: no SPI5 node here, so no marker" +# gnssd not up yet when a client asks: the 9a's start waits for it while the modem unit brings it +# (OMAMOBILE_MODEM_GNSS=1), and without it holds the connection a moment before giving up, so a client +# that reconnects at once can't run the unit into systemd's start limit +cat > "$tmp/systemctl" <<'EOF' +#!/bin/bash +case "$*" in + *ActiveState*) echo "${FAKE_STATE:-inactive}" ;; + *Environment*) echo "${FAKE_ENV:-}" ;; +esac +EOF +chmod +x "$tmp/systemctl" +export OMAMOBILE_GNSS_SYSTEMCTL=$tmp/systemctl +printf 'google,zumapro-tegu\0google,zumapro\0' > "$tmp/dt/compatible" +rm -f "$tmp/var/lib/omamobile/gnss-bringup-started" +: > "$tmp/log"; : > "$tmp/unix-late" +t0=$SECONDS +OMAMOBILE_GNSS_NOTHING_HOLD=2 OMAMOBILE_GNSS_GNSSD_WAIT=5 FAKE_STATE=inactive run_start "$tmp/dt" "$tmp/unix-late" || fail "no gnssd: the start fails" +(( SECONDS - t0 >= 2 )) || fail "no gnssd and none coming: the connection is held before giving up" +grep -c 'gnss-slsi start' "$tmp/log" >/dev/null && fail "no gnssd: gnss-slsi started" +FAKE_STATE=active FAKE_ENV="OMAMOBILE_MODEM_GNSS=0 X=1" OMAMOBILE_GNSS_NOTHING_HOLD=0 OMAMOBILE_GNSS_GNSSD_WAIT=5 \ + run_start "$tmp/dt" "$tmp/unix-late" || fail "a modem without GNSS: the start fails" +grep -c 'gnss-slsi start' "$tmp/log" >/dev/null && fail "a modem without GNSS: gnss-slsi started" +t0=$SECONDS +FAKE_STATE=active FAKE_ENV="X=1 OMAMOBILE_MODEM_GNSS=1" OMAMOBILE_GNSS_NOTHING_HOLD=0 OMAMOBILE_GNSS_GNSSD_WAIT=2 \ + run_start "$tmp/dt" "$tmp/unix-late" || fail "gnssd never came: the start fails" +(( SECONDS - t0 >= 2 )) || fail "gnssd coming: the start waits for it" +grep -c 'gnss-slsi start' "$tmp/log" >/dev/null && fail "gnssd never came: gnss-slsi started" +( sleep 1; printf '@GNSSND\n' > "$tmp/unix-late" ) & +FAKE_STATE=activating FAKE_ENV="OMAMOBILE_MODEM_GNSS=1" OMAMOBILE_GNSS_NOTHING_HOLD=0 OMAMOBILE_GNSS_GNSSD_WAIT=10 \ + run_start "$tmp/dt" "$tmp/unix-late" || fail "gnssd came late: the start fails" +wait +grep -c 'chroot gnss-slsi start' "$tmp/log" >/dev/null || fail "gnssd came during the wait: gnss-slsi starts" +unset OMAMOBILE_GNSS_SYSTEMCTL +rm -f "$tmp/var/lib/omamobile/gnss-bringup-started" +echo "ok - a request before gnssd is up waits for it while the modem brings it, and without it holds a moment before giving up" + rm -rf "$tmp" echo "ok - the 9a's marker survives failed stops and clears only after a clean stop" grep -c 'OMAMOBILE_GNSS_NMEA_OUT=fifo' lib/omamobile-gnss-start >/dev/null || fail "the 9a's NMEA goes to the FIFO" diff --git a/packages/omamobile-gnss/version b/packages/omamobile-gnss/version index 13dead7eb..f2722b133 100644 --- a/packages/omamobile-gnss/version +++ b/packages/omamobile-gnss/version @@ -1 +1 @@ -0.2.10 +0.2.12 From 4a875b2334124adbf3e200bcd21a5b40aff7947c Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Wed, 18 Nov 2026 21:35:40 -0649 Subject: [PATCH 2/4] omamobile-gnss 0.2.12: a reboot during a location session no longer leaves GNSS off on the Pixel 9a At a reboot, and at the bridge's idle exit, the NMEA bridge stops before the GNSS stack it is ordered after. The 9a's client then wrote NMEA into a FIFO with no reader, SIGPIPE killed it, and the profile stopped itself before systemd's stop came: an unexpected exit, so the hang marker stayed, and every later boot skipped GNSS ("the last bring-up ... never finished") until --retry, leaving apps only GeoClue's IP positions. The skip also exited at once, so GeoClue's reconnects hit the socket's trigger limit and failed it for the rest of the boot, and a request after --retry found nothing listening. Now the profile spawns the client with SIGPIPE ignored, so it stays until the stack is stopped; the stack is ordered after the 9a's modem unit, so at shutdown it also stops before gnssd goes; and the skip holds the connection 5 s, as "nothing to do" does. Tested: test/all checks the client's SIGPIPE disposition around its spawn, the ordering and the hold on a leftover marker. On a Pixel 9a on the published kernel, with the bridge stopped first during a session, the stack stopped cleanly and the marker went; then 8 reboots, each with a session running at the reboot, left no marker, where before the fix 4 of 8 boots skipped GNSS after the first such reboot. --- .../omamobile-gnss/lib/omamobile-gnss-start | 4 +++ .../omamobile-gnss/profiles/gnss-slsi.conf | 9 +++++++ packages/omamobile-gnss/test/all | 25 +++++++++++++++++++ .../systemd/system/omamobile-gnss.service | 4 +++ 4 files changed, 42 insertions(+) diff --git a/packages/omamobile-gnss/lib/omamobile-gnss-start b/packages/omamobile-gnss/lib/omamobile-gnss-start index c4ef468b6..4b7ad9a10 100755 --- a/packages/omamobile-gnss/lib/omamobile-gnss-start +++ b/packages/omamobile-gnss/lib/omamobile-gnss-start @@ -79,6 +79,10 @@ if [[ ${1:-} == --retry ]]; then elif [[ -e $MARK ]]; then if tegu; then say "the last bring-up ($(cat "$MARK")) never finished; skipping GNSS (/usr/lib/omamobile-vendor/omamobile-gnss-start --retry clears the marker; the next location request then starts GNSS)" + # Held as "nothing to do" below is: GeoClue reconnects at once, and five + # quick exits failed the socket (trigger limit) for the rest of the boot, + # so after --retry the next request still found nothing listening. + sleep "$NOTHING_HOLD" else say "the last bring-up ($(cat "$MARK")) never finished; skipping GNSS (run /usr/lib/omamobile-vendor/omamobile-gnss-start --retry)" fi diff --git a/packages/omamobile-gnss/profiles/gnss-slsi.conf b/packages/omamobile-gnss/profiles/gnss-slsi.conf index 1ee6363f6..b64f4cb1e 100644 --- a/packages/omamobile-gnss/profiles/gnss-slsi.conf +++ b/packages/omamobile-gnss/profiles/gnss-slsi.conf @@ -52,9 +52,18 @@ profile_start() { sleep 1 spawn hal vendor /vendor/bin/hw/android.hardware.gnss-service sleep 3 + # The client writes the HAL's NMEA into the FIFO the bridge reads, and the + # bridge stops before this stack (it is ordered after it): at shutdown, and + # at its idle exit. A write with no reader raised SIGPIPE and killed the + # client, the profile then stopped itself before systemd's stop came, and + # that unexpected exit kept the hang marker, so the next boot skipped GNSS. + # With SIGPIPE ignored the write fails and the client stays until the stack + # is stopped. + trap '' PIPE if [[ $NMEA_OUT == fifo ]]; then spawn client vendor /omamobile/bin/omamobile-gnss-client /data/vendor/gps/nmea_out "$GNSS_SERVICE" else spawn client vendor /omamobile/bin/omamobile-gnss-client - "$GNSS_SERVICE" fi + trap - PIPE } diff --git a/packages/omamobile-gnss/test/all b/packages/omamobile-gnss/test/all index 8dba39652..b35c12896 100755 --- a/packages/omamobile-gnss/test/all +++ b/packages/omamobile-gnss/test/all @@ -39,6 +39,8 @@ run_start() { # $1 dt dir, $2 fake unix table -e "s|/usr/lib/omamobile-vendor/omamobile-vendor-chroot|'"$tmp"'/stub|" lib/omamobile-gnss-start > '"$tmp"'/start bash '"$tmp"'/start "$@"' _ "${3:-}" 2>/dev/null } +# The starts below that skip GNSS hold the client's connection first; not here, unless a case asks. +export OMAMOBILE_GNSS_NOTHING_HOLD=0 : > "$tmp/log"; printf '@GNSSND\n' > "$tmp/unix" run_start "$tmp/dt" "$tmp/unix" grep -c 'chroot gnss-slsi start' "$tmp/log" >/dev/null || fail "9a branch: gnss-slsi start ran" @@ -127,6 +129,29 @@ grep -c 'chroot gnss-slsi start' "$tmp/log" >/dev/null || fail "gnssd came durin unset OMAMOBILE_GNSS_SYSTEMCTL rm -f "$tmp/var/lib/omamobile/gnss-bringup-started" echo "ok - a request before gnssd is up waits for it while the modem brings it, and without it holds a moment before giving up" +# A marker left by a bring-up that never finished: the 9a skips GNSS, keeps the marker, and holds the +# connection first, so GeoClue's reconnects can't fail the socket and --retry's next request finds it listening +date -Is > "$tmp/var/lib/omamobile/gnss-bringup-started" +: > "$tmp/log"; t0=$SECONDS +OMAMOBILE_GNSS_NOTHING_HOLD=2 run_start "$tmp/dt" "$tmp/unix" || fail "a leftover marker: the start fails" +(( SECONDS - t0 >= 2 )) || fail "a leftover marker on the 9a: the connection is held before the skip" +grep -c 'gnss-slsi start' "$tmp/log" >/dev/null && fail "a leftover marker: gnss-slsi started" +[[ -e "$tmp/var/lib/omamobile/gnss-bringup-started" ]] || fail "a leftover marker: the skip keeps it" +rm -f "$tmp/var/lib/omamobile/gnss-bringup-started" +echo "ok - a leftover marker skips GNSS on the 9a after holding the connection, and stays" +grep -qx 'After=omamobile-tegu-modem.service' vendor/systemd/system/omamobile-gnss.service \ + || fail "the GNSS stack stops before the 9a's modem unit at shutdown" +grep -E '^(Requires|Wants|BindsTo)=.*omamobile-tegu-modem' vendor/systemd/system/omamobile-gnss.service \ + && fail "the GNSS stack must not pull the modem in" +echo "ok - at shutdown the GNSS stack stops before the 9a's modem, which it never starts" +# The client survives the bridge going first: SIGPIPE ignored for its spawn (inherited across exec), and only for it +awk '/^profile_start\(\)/,/^}/' profiles/gnss-slsi.conf > "$tmp/ps" +grep -n "trap '' PIPE" "$tmp/ps" | head -1 | cut -d: -f1 > "$tmp/ign"; grep -n 'spawn client' "$tmp/ps" | head -1 | cut -d: -f1 > "$tmp/cl" +grep -n 'trap - PIPE' "$tmp/ps" | head -1 | cut -d: -f1 > "$tmp/rst"; grep -n 'spawn hal' "$tmp/ps" | head -1 | cut -d: -f1 > "$tmp/hal" +[[ -s $tmp/ign && -s $tmp/cl && -s $tmp/rst && -s $tmp/hal ]] || fail "the 9a's profile ignores SIGPIPE around the client's spawn" +(( $(<"$tmp/hal") < $(<"$tmp/ign") && $(<"$tmp/ign") < $(<"$tmp/cl") && $(<"$tmp/cl") < $(<"$tmp/rst") )) \ + || fail "SIGPIPE is ignored for the client only, after the HAL's spawn and back to default after it" +echo "ok - the 9a's client outlives a bridge that stops first, so the stack's stop stays a clean one" rm -rf "$tmp" echo "ok - the 9a's marker survives failed stops and clears only after a clean stop" diff --git a/packages/omamobile-gnss/vendor/systemd/system/omamobile-gnss.service b/packages/omamobile-gnss/vendor/systemd/system/omamobile-gnss.service index 355a6e6fc..86bb9d8e8 100644 --- a/packages/omamobile-gnss/vendor/systemd/system/omamobile-gnss.service +++ b/packages/omamobile-gnss/vendor/systemd/system/omamobile-gnss.service @@ -7,6 +7,10 @@ [Unit] Description=Omarchy Mobile GNSS (Pixel 7 Pro: BCM4775x, stock lhd and gpsd; Pixel 9a: the modem's Kepler through the stock HAL) After=network-online.target +# The 9a's gnssd runs in the modem's unit: stopped after it at shutdown, a +# session ends before gnssd goes, so a reboot mid-session is a clean stop and +# clears the hang marker. Ordering only; nothing here starts the modem. +After=omamobile-tegu-modem.service StopWhenUnneeded=yes ConditionPathExists=|/usr/lib/omamobile-vendor/gnss/root ConditionPathExists=|/usr/lib/omamobile-vendor/gnss-slsi/root From 5e92a4173b1c24323db3be805981bec533124576 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 19 Nov 2026 02:15:37 -0649 Subject: [PATCH 3/4] omamobile-gnss 0.2.12: on the Pixel 9a the receiver stops when a location session ends The client stops positioning through the HAL (stopNmea, then stop) when it gets TERM, but the runner's stop signals every daemon of the profile at once, and the HAL went before the client's stop reached it. gnssd then kept the receiver running, with the GNSS core streaming over SPI, until the next boot: after any location request, gnssd used about 10 % of a core and the kernel's SPI driver on a bring-up kernel logged over 100 lines a second. Now the gnss-slsi profile has a graceful stop (profile_stop, which the runner calls from the host before systemd signals the daemons): it signals the client alone, while the HAL is still there, and waits up to 3 s. A stop-requested file in the profile's run directory, written first, tells the runner that this exit is part of the stop, so it stops the rest cleanly instead of reporting "a service exited", and the hang marker's clean-stop rule still holds. A new start removes an old file. Tested: test/all runs profile_stop with a stand-in client and checks the file, the signal and the runner's clean-stop line. On a Pixel 9a after a session: before the change, gnss_spi logged 171 lines a second and gnssd used 86 ms of CPU a second after the stack had stopped, and the drain with the screen off was 408 mA against 309 mA after a fresh boot; with it, both fell to 0 when the stack stopped, the marker cleared, and the drain read 296 mA. --- .../lib/omamobile-vendor-chroot | 8 ++++++- .../omamobile-gnss/profiles/gnss-slsi.conf | 20 ++++++++++++++++ packages/omamobile-gnss/test/all | 23 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/packages/omamobile-gnss/lib/omamobile-vendor-chroot b/packages/omamobile-gnss/lib/omamobile-vendor-chroot index d2e21a669..2bd72e001 100755 --- a/packages/omamobile-gnss/lib/omamobile-vendor-chroot +++ b/packages/omamobile-gnss/lib/omamobile-vendor-chroot @@ -86,6 +86,11 @@ profile_stop() { :; } source "$PROFILE_CONF" ROOT=$RUN/root NSPID=$RUN/ns.pid +# A profile's graceful stop (profile_stop, from the host) may end one of its +# daemons on purpose before systemd's stop signals the rest; it writes this +# file first, and the supervision below then takes that exit as part of the +# stop: a clean one, not "a service exited". +STOP_REQUESTED=$RUN/stop-requested LIBS_VENDOR=/vendor/lib64:/vendor/lib64/hw:/system/lib64:/omamobile/lib64 LIBS_SYSTEM=/system/lib64:/vendor/lib64:/omamobile/lib64 @@ -282,7 +287,7 @@ start() { check mkdir -p "$RUN" if [[ -z ${OMAMOBILE_VENDOR_IN_NS:-} ]]; then - rm -f "$NSPID" + rm -f "$NSPID" "$STOP_REQUESTED" exec unshare --mount --propagation private --pid --fork --kill-child \ env OMAMOBILE_VENDOR_IN_NS=1 "$0" "$PROFILE" start fi @@ -299,6 +304,7 @@ start() { # whether to restart it). wait -n || true # wait also returns when TERM/INT arrives; then the trap is already stopping + [[ -e $STOP_REQUESTED ]] && stop 0 [[ -n $STOPPING ]] || say "a service exited" stop 1 } diff --git a/packages/omamobile-gnss/profiles/gnss-slsi.conf b/packages/omamobile-gnss/profiles/gnss-slsi.conf index b64f4cb1e..d94a11ded 100644 --- a/packages/omamobile-gnss/profiles/gnss-slsi.conf +++ b/packages/omamobile-gnss/profiles/gnss-slsi.conf @@ -47,6 +47,26 @@ profile_setup() { # registers android.hardware.gnss.IGnss/vendor there. GNSS_SERVICE=${OMAMOBILE_GNSS_SERVICE:-android.hardware.gnss.IGnss/vendor} +# A graceful stop, from the host before systemd signals the daemons. The +# client stops positioning through the HAL (stopNmea, stop) when it gets TERM, +# but the runner's stop signals every daemon at once, and the HAL went before +# the client's stop reached it: gnssd kept the receiver running, with the +# GNSS core streaming over SPI, until the next boot. So the client goes first +# and alone, while the HAL is still there; the stop-requested file tells the +# runner its exit is part of this stop. +profile_stop() { + local pid + pid=$(pgrep -f '^/omamobile/bin/omamobile-gnss-client ' | head -1) || return 0 + [[ -n $pid ]] || return 0 + : > "$STOP_REQUESTED" + kill -TERM "$pid" 2>/dev/null || return 0 + for _ in $(seq 1 30); do + kill -0 "$pid" 2>/dev/null || return 0 + sleep 0.1 + done + say "the client did not stop within 3 s" +} + profile_start() { spawn vndservicemanager vendor /vendor/bin/vndservicemanager /dev/vndbinder sleep 1 diff --git a/packages/omamobile-gnss/test/all b/packages/omamobile-gnss/test/all index b35c12896..a777148fa 100755 --- a/packages/omamobile-gnss/test/all +++ b/packages/omamobile-gnss/test/all @@ -152,6 +152,29 @@ grep -n 'trap - PIPE' "$tmp/ps" | head -1 | cut -d: -f1 > "$tmp/rst"; grep -n 's (( $(<"$tmp/hal") < $(<"$tmp/ign") && $(<"$tmp/ign") < $(<"$tmp/cl") && $(<"$tmp/cl") < $(<"$tmp/rst") )) \ || fail "SIGPIPE is ignored for the client only, after the HAL's spawn and back to default after it" echo "ok - the 9a's client outlives a bridge that stops first, so the stack's stop stays a clean one" +# The 9a's graceful stop: the client alone first, with the stop-requested file written before its signal, so it +# can stop the receiver through the HAL; the runner takes that exit as a clean stop +sleep 30 & fake=$! +mkdir -p "$tmp/run-ps" +out=$(STOP_REQUESTED="$tmp/run-ps/stop-requested" FAKE=$fake bash -c ' + say() { echo "say: $*"; } + pgrep() { [[ $* == "-f ^/omamobile/bin/omamobile-gnss-client " ]] && echo "$FAKE"; } + source <(awk "/^profile_stop\\(\\)/,/^}/" profiles/gnss-slsi.conf) + profile_stop + echo "returned"' 2>&1) +grep -qx returned <<<"$out" || fail "profile_stop returns" +[[ -e $tmp/run-ps/stop-requested ]] || fail "profile_stop writes the stop-requested file" +rc=0; wait "$fake" || rc=$? +(( rc == 143 )) || { kill "$fake" 2>/dev/null; fail "profile_stop sends the client TERM"; } +out=$(STOP_REQUESTED="$tmp/run-ps/none" bash -c ' + say() { :; }; pgrep() { return 1; } + source <(awk "/^profile_stop\\(\\)/,/^}/" profiles/gnss-slsi.conf) + profile_stop; echo "returned"') +[[ $out == returned && ! -e $tmp/run-ps/none ]] || fail "no client: profile_stop writes nothing and returns" +grep -n 'wait -n || true' -A 2 lib/omamobile-vendor-chroot | grep -c '\[\[ -e $STOP_REQUESTED \]\] && stop 0' >/dev/null \ + || fail "the runner takes a requested stop's exit as clean" +grep -q 'rm -f "$NSPID" "$STOP_REQUESTED"' lib/omamobile-vendor-chroot || fail "a new start drops an old stop-requested file" +echo "ok - the 9a's stop ends the client first, through the HAL, and the runner calls that a clean stop" rm -rf "$tmp" echo "ok - the 9a's marker survives failed stops and clears only after a clean stop" From f326aef6f5f6c68d43b3dadd732ef48704cd21e5 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 19 Nov 2026 14:08:51 -0649 Subject: [PATCH 4/4] omamobile-gnss 0.2.12: the 9a's wait and hold run without the sleep inhibitor, and the hold watches for the modem Reading my own three commits again: with the modem off, the 5 s hold made the unit start every 5 s for as long as a client asked, each time under the unit's sleep inhibitor, so a 9a with no modem was kept awake by a position it couldn't have. The unit now starts the script itself and the script takes the inhibitor: at once on the 7 Pro, as its unit always did, and on the 9a only around a session. The hold is 60 s and looks every 5 s whether the modem's unit has started, then waits for its gnssd; a client that keeps asking with the modem off starts the unit once a minute, not kept awake. The wait reads /proc/net/unix with a builtin. The stop finds the client with pgrep -o (procps-ng is now a dependency), and the unit's comment says which unit stops first. Tests: the "doesn't wait" cases have upper bounds, a give-up is checked to leave no marker, session or inhibitor, the stop-requested file is checked to exist when the client gets its signal, and the runner's own stop and supervision lines are run with and without the file. Seventeen mutations of the new code each fail the suite with a FAIL line. Not yet run on a phone. --- packages/omamobile-gnss/PKGBUILD | 2 +- .../omamobile-gnss/lib/omamobile-gnss-start | 49 +++++-- .../omamobile-gnss/profiles/gnss-slsi.conf | 2 +- packages/omamobile-gnss/test/all | 133 +++++++++++++----- .../systemd/system/omamobile-gnss.service | 14 +- 5 files changed, 144 insertions(+), 56 deletions(-) diff --git a/packages/omamobile-gnss/PKGBUILD b/packages/omamobile-gnss/PKGBUILD index e5964331a..128411283 100644 --- a/packages/omamobile-gnss/PKGBUILD +++ b/packages/omamobile-gnss/PKGBUILD @@ -7,7 +7,7 @@ pkgdesc="Omarchy Mobile GNSS for the Pixel 7 Pro: Broadcom's lhd/gpsd in a vendo arch=(aarch64) url="https://github.com/derekross/omarchy-mobile" license=(MIT) -depends=(bash python curl iproute2 util-linux coreutils systemd geoclue libnotify) +depends=(bash python curl iproute2 util-linux coreutils procps-ng systemd geoclue libnotify) optdepends=('gpsd: NMEA for gpsd clients through /run/omamobile-gnss/nmea-tty') backup=(etc/geoclue/conf.d/90-omamobile-gnss.conf etc/omamobile/gnss.conf) install=omamobile-gnss.install diff --git a/packages/omamobile-gnss/lib/omamobile-gnss-start b/packages/omamobile-gnss/lib/omamobile-gnss-start index 4b7ad9a10..e4bc5a064 100755 --- a/packages/omamobile-gnss/lib/omamobile-gnss-start +++ b/packages/omamobile-gnss/lib/omamobile-gnss-start @@ -21,12 +21,22 @@ say() { printf 'omamobile-gnss: %s\n' "$*" >&2; } # modem unit runs with OMAMOBILE_MODEM_GNSS=1; a location request in that # window waits for it (GNSSD_WAIT s at most) rather than finding nothing. GNSSD_WAIT=${OMAMOBILE_GNSS_GNSSD_WAIT:-90} -# Without gnssd the start holds the client's connection this long before it -# exits: a client that reconnects at once (GeoClue) would otherwise start the -# unit five times in a second, and systemd's start limit would fail it and -# its socket for the rest of the boot. -NOTHING_HOLD=${OMAMOBILE_GNSS_NOTHING_HOLD:-5} -gnssd_up() { grep -c '@GNSSND' /proc/net/unix >/dev/null; } +# Without gnssd, and with no modem unit bringing it, the start holds the +# client's connection this long before it exits, looking every 5 s whether +# the modem has started meanwhile: a client that reconnects at once (GeoClue) +# would otherwise start the unit five times in a second, and systemd's start +# limit would fail it and its socket for the rest of the boot. A client that +# keeps asking with the modem off so starts the unit once a minute. +NOTHING_HOLD=${OMAMOBILE_GNSS_NOTHING_HOLD:-60} +# The sleep inhibitor (block mode), which logind and omamobile-sleepd honour +# (device/cheetah/SUSPEND-PLAN.md 6.1). The 7 Pro holds it for the whole +# start, as its unit always did. The 9a takes it for a session only: the +# wait and the hold above run without it, so a 9a whose modem is off isn't +# kept awake by a client that asks for a position it can't have. +INHIBIT=("${OMAMOBILE_GNSS_INHIBIT:-/usr/bin/systemd-inhibit}" --what=sleep --mode=block + "--who=Omarchy Mobile GNSS" "--why=A location session is running") +# Read with a builtin: this runs once a second while it waits. +gnssd_up() { [[ $(< /proc/net/unix) == *@GNSSND* ]]; } gnssd_coming() { local state env state=$(${OMAMOBILE_GNSS_SYSTEMCTL:-systemctl} show -p ActiveState --value omamobile-tegu-modem.service 2>/dev/null) || return 1 @@ -68,6 +78,10 @@ if [[ ${1:-} == --stop ]]; then exec /usr/lib/omamobile-vendor/omamobile-vendor-chroot "$profile" stop fi +if [[ $# -eq 0 && -z ${OMAMOBILE_GNSS_INHIBITED:-} ]] && ! tegu; then + OMAMOBILE_GNSS_INHIBITED=1 exec "${INHIBIT[@]}" "$0" +fi + if [[ ${1:-} == --retry ]]; then rm -f "$MARK" # By hand on the 9a this only clears the marker: GNSS starts inside its @@ -93,16 +107,23 @@ fi # the modem profile, and the gnss-slsi profile runs the HAL and our client, # which writes NMEA to the FIFO the bridge reads. Nothing to load here. if tegu; then - if ! gnssd_up && gnssd_coming; then - say "waiting for gnssd: the modem profile starts it some 20 s after the modem is ONLINE" - for ((i = 0; i < GNSSD_WAIT; i++)); do - gnssd_up && break + # Before the marker and the session: a give-up here leaves nothing behind. + coming=0 idle=0 told= + until gnssd_up; do + if gnssd_coming; then + [[ -n $told ]] || say "waiting for gnssd: the modem profile starts it some 20 s after the modem is ONLINE" + told=1 + ((coming++ < GNSSD_WAIT)) || break sleep 1 - done - fi + else + ((idle < NOTHING_HOLD)) || break + step=$((NOTHING_HOLD - idle < 5 ? NOTHING_HOLD - idle : 5)) + sleep "$step" + idle=$((idle + step)) + fi + done if ! gnssd_up; then say "gnssd isn't running (the modem profile with OMAMOBILE_MODEM_GNSS=1); nothing to do" - sleep "$NOTHING_HOLD" exit 0 fi # The HAL client is in the package only when it was built with @@ -126,7 +147,7 @@ if tegu; then printf '%s\n' "$INVOCATION_ID" > "$SESSION" sync say "starting the 9a's GNSS HAL and client" - OMAMOBILE_GNSS_NMEA_OUT=fifo exec /usr/lib/omamobile-vendor/omamobile-vendor-chroot gnss-slsi start + OMAMOBILE_GNSS_NMEA_OUT=fifo exec "${INHIBIT[@]}" /usr/lib/omamobile-vendor/omamobile-vendor-chroot gnss-slsi start fi # The DT must have the GNSS node enabled (gnss overlay); otherwise nothing to do. if ! grep -qs okay /sys/firmware/devicetree/base/soc@0/usi@109400c0/spi@10940000/status; then diff --git a/packages/omamobile-gnss/profiles/gnss-slsi.conf b/packages/omamobile-gnss/profiles/gnss-slsi.conf index d94a11ded..3d09fe4a1 100644 --- a/packages/omamobile-gnss/profiles/gnss-slsi.conf +++ b/packages/omamobile-gnss/profiles/gnss-slsi.conf @@ -56,7 +56,7 @@ GNSS_SERVICE=${OMAMOBILE_GNSS_SERVICE:-android.hardware.gnss.IGnss/vendor} # runner its exit is part of this stop. profile_stop() { local pid - pid=$(pgrep -f '^/omamobile/bin/omamobile-gnss-client ' | head -1) || return 0 + pid=$(pgrep -o -f '^/omamobile/bin/omamobile-gnss-client ') || return 0 [[ -n $pid ]] || return 0 : > "$STOP_REQUESTED" kill -TERM "$pid" 2>/dev/null || return 0 diff --git a/packages/omamobile-gnss/test/all b/packages/omamobile-gnss/test/all index a777148fa..5ed30918a 100755 --- a/packages/omamobile-gnss/test/all +++ b/packages/omamobile-gnss/test/all @@ -6,7 +6,7 @@ set -euo pipefail cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." fail() { echo "FAIL: $*" >&2; exit 1; } for f in bin/omamobile-gnss lib/omamobile-vendor-chroot lib/omamobile-gnss-start lib/omamobile-gnss-lto \ - lib/omamobile-gnss-conf install profiles/gnss.conf omamobile-gnss.install; do + lib/omamobile-gnss-conf install profiles/gnss.conf profiles/gnss-slsi.conf omamobile-gnss.install; do bash -n "$f" || fail "syntax: $f" done python3 -c 'import ast, sys; ast.parse(open(sys.argv[1]).read())' lib/omamobile-gnss-nmea || fail "python: omamobile-gnss-nmea" @@ -27,6 +27,15 @@ echo "chroot $*" >> "${STUB_LOG}" [ "${STUB_FAIL:-0}" != 1 ] || [ "$2" != stop ] EOF chmod +x "$tmp/stub" +# systemd-inhibit's stand-in: says it was asked, then runs the command +cat > "$tmp/inhibit" <<'EOF' +#!/bin/sh +echo "inhibit $*" >> "${STUB_LOG}" +while [ "${1#--}" != "$1" ]; do shift; done +exec "$@" +EOF +chmod +x "$tmp/inhibit" +export OMAMOBILE_GNSS_INHIBIT=$tmp/inhibit run_start() { # $1 dt dir, $2 fake unix table STUB_LOG="$tmp/log" OMAMOBILE_DT="$1" OMAMOBILE_GNSS_CLIENT="${TEST_CLIENT-$tmp/stub}" INVOCATION_ID="${TEST_INVOCATION_ID-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}" \ SERVICE_RESULT="${TEST_SERVICE_RESULT:-success}" MAINPID="${TEST_MAINPID-123}" STUB_FAIL="${TEST_STUB_FAIL:-0}" bash -c ' @@ -37,7 +46,8 @@ run_start() { # $1 dt dir, $2 fake unix table -e "s|/run/omamobile-gnss/stop-request|'"$tmp"'/run/omamobile-gnss/stop-request|" \ -e "s|/sys/firmware/devicetree/base/soc@0/usi@109400c0/spi@10940000/status|'"$tmp"'/no-spi5|" \ -e "s|/usr/lib/omamobile-vendor/omamobile-vendor-chroot|'"$tmp"'/stub|" lib/omamobile-gnss-start > '"$tmp"'/start - bash '"$tmp"'/start "$@"' _ "${3:-}" 2>/dev/null + chmod +x '"$tmp"'/start + if [ -n "$1" ]; then bash '"$tmp"'/start "$1"; else bash '"$tmp"'/start; fi' _ "${3:-}" 2>/dev/null } # The starts below that skip GNSS hold the client's connection first; not here, unless a case asks. export OMAMOBILE_GNSS_NOTHING_HOLD=0 @@ -94,11 +104,27 @@ grep -c 'gnss-slsi start' "$tmp/log" >/dev/null && fail "9a branch: a start with run_start "$tmp/dt" "$tmp/unix" grep -c 'gnss-slsi' "$tmp/log" >/dev/null && fail "7 Pro branch: must not touch gnss-slsi" [[ ! -e "$tmp/var/lib/omamobile/gnss-bringup-started" ]] || fail "7 Pro branch: no SPI5 node here, so no marker" +# The sleep inhibitor is the start's own (the unit's ExecStart is the plain script): the 7 Pro takes it at +# once, as its unit always did, and the 9a only around a session +grep -c '^inhibit --what=sleep --mode=block --who=Omarchy Mobile GNSS --why=A location session is running ' "$tmp/log" >/dev/null \ + || fail "7 Pro branch: the start runs under the sleep inhibitor" +[[ $(grep -c '^inhibit ' "$tmp/log") == 1 ]] || fail "7 Pro branch: the inhibitor is taken once" +printf 'google,zumapro-tegu\0google,zumapro\0' > "$tmp/dt/compatible" +: > "$tmp/log"; rm -f "$tmp/var/lib/omamobile/gnss-bringup-started" +run_start "$tmp/dt" "$tmp/unix" +[[ $(grep -n '^inhibit .* gnss-slsi start$' "$tmp/log" | cut -d: -f1) == 1 && $(grep -c '^chroot gnss-slsi start$' "$tmp/log") == 1 ]] \ + || fail "9a branch: the session runs under the sleep inhibitor" +rm -f "$tmp/var/lib/omamobile/gnss-bringup-started" +grep -c -x 'ExecStart=/usr/lib/omamobile-vendor/omamobile-gnss-start' vendor/systemd/system/omamobile-gnss.service >/dev/null \ + || fail "the unit starts the script itself, which takes the inhibitor" +echo "ok - the 7 Pro's start and the 9a's session hold the sleep inhibitor" # gnssd not up yet when a client asks: the 9a's start waits for it while the modem unit brings it -# (OMAMOBILE_MODEM_GNSS=1), and without it holds the connection a moment before giving up, so a client -# that reconnects at once can't run the unit into systemd's start limit +# (OMAMOBILE_MODEM_GNSS=1), and otherwise holds the connection, looking for the modem, before giving up, so a +# client that reconnects at once can't run the unit into systemd's start limit. Neither holds the inhibitor, +# and a give-up leaves no marker. cat > "$tmp/systemctl" <<'EOF' #!/bin/bash +[[ -z ${FAKE_FILE:-} ]] || source "$FAKE_FILE" case "$*" in *ActiveState*) echo "${FAKE_STATE:-inactive}" ;; *Environment*) echo "${FAKE_ENV:-}" ;; @@ -106,29 +132,53 @@ esac EOF chmod +x "$tmp/systemctl" export OMAMOBILE_GNSS_SYSTEMCTL=$tmp/systemctl -printf 'google,zumapro-tegu\0google,zumapro\0' > "$tmp/dt/compatible" -rm -f "$tmp/var/lib/omamobile/gnss-bringup-started" -: > "$tmp/log"; : > "$tmp/unix-late" +gave_up() { # $1 what: nothing started, nothing left, no inhibitor + grep -c 'gnss-slsi start' "$tmp/log" >/dev/null && fail "$1: gnss-slsi started" + grep -c '^inhibit ' "$tmp/log" >/dev/null && fail "$1: the sleep inhibitor was taken" + [[ ! -e "$tmp/var/lib/omamobile/gnss-bringup-started" && ! -e "$tmp/run/omamobile-gnss/session" ]] || fail "$1: a give-up left a marker or a session" +} +: > "$tmp/log"; : > "$tmp/unix-late"; rm -f "$tmp/run/omamobile-gnss/session" "$tmp/run/omamobile-gnss/stop-request" t0=$SECONDS -OMAMOBILE_GNSS_NOTHING_HOLD=2 OMAMOBILE_GNSS_GNSSD_WAIT=5 FAKE_STATE=inactive run_start "$tmp/dt" "$tmp/unix-late" || fail "no gnssd: the start fails" +OMAMOBILE_GNSS_NOTHING_HOLD=2 OMAMOBILE_GNSS_GNSSD_WAIT=30 FAKE_STATE=inactive run_start "$tmp/dt" "$tmp/unix-late" || fail "no gnssd: the start fails" (( SECONDS - t0 >= 2 )) || fail "no gnssd and none coming: the connection is held before giving up" -grep -c 'gnss-slsi start' "$tmp/log" >/dev/null && fail "no gnssd: gnss-slsi started" -FAKE_STATE=active FAKE_ENV="OMAMOBILE_MODEM_GNSS=0 X=1" OMAMOBILE_GNSS_NOTHING_HOLD=0 OMAMOBILE_GNSS_GNSSD_WAIT=5 \ +(( SECONDS - t0 < 8 )) || fail "no gnssd and none coming: the hold is NOTHING_HOLD, not the wait for a modem" +gave_up "no gnssd and no modem" +t0=$SECONDS +FAKE_STATE=inactive FAKE_ENV="OMAMOBILE_MODEM_GNSS=1" OMAMOBILE_GNSS_NOTHING_HOLD=0 OMAMOBILE_GNSS_GNSSD_WAIT=30 \ + run_start "$tmp/dt" "$tmp/unix-late" || fail "a stopped modem unit: the start fails" +(( SECONDS - t0 < 8 )) || fail "a modem unit that isn't running isn't waited for" +gave_up "a stopped modem unit" +t0=$SECONDS +FAKE_STATE=active FAKE_ENV="OMAMOBILE_MODEM_GNSS=0 X=1" OMAMOBILE_GNSS_NOTHING_HOLD=0 OMAMOBILE_GNSS_GNSSD_WAIT=30 \ run_start "$tmp/dt" "$tmp/unix-late" || fail "a modem without GNSS: the start fails" -grep -c 'gnss-slsi start' "$tmp/log" >/dev/null && fail "a modem without GNSS: gnss-slsi started" +(( SECONDS - t0 < 8 )) || fail "a modem started without GNSS isn't waited for" +gave_up "a modem without GNSS" t0=$SECONDS FAKE_STATE=active FAKE_ENV="X=1 OMAMOBILE_MODEM_GNSS=1" OMAMOBILE_GNSS_NOTHING_HOLD=0 OMAMOBILE_GNSS_GNSSD_WAIT=2 \ run_start "$tmp/dt" "$tmp/unix-late" || fail "gnssd never came: the start fails" (( SECONDS - t0 >= 2 )) || fail "gnssd coming: the start waits for it" -grep -c 'gnss-slsi start' "$tmp/log" >/dev/null && fail "gnssd never came: gnss-slsi started" +gave_up "gnssd never came" ( sleep 1; printf '@GNSSND\n' > "$tmp/unix-late" ) & -FAKE_STATE=activating FAKE_ENV="OMAMOBILE_MODEM_GNSS=1" OMAMOBILE_GNSS_NOTHING_HOLD=0 OMAMOBILE_GNSS_GNSSD_WAIT=10 \ +t0=$SECONDS +FAKE_STATE=activating FAKE_ENV="OMAMOBILE_MODEM_GNSS=1" OMAMOBILE_GNSS_NOTHING_HOLD=0 OMAMOBILE_GNSS_GNSSD_WAIT=30 \ run_start "$tmp/dt" "$tmp/unix-late" || fail "gnssd came late: the start fails" wait +(( SECONDS - t0 < 10 )) || fail "gnssd came during the wait: the start goes on at once" grep -c 'chroot gnss-slsi start' "$tmp/log" >/dev/null || fail "gnssd came during the wait: gnss-slsi starts" +[[ -e "$tmp/var/lib/omamobile/gnss-bringup-started" ]] || fail "gnssd came during the wait: the marker goes down with the session" +# the modem started during the hold: seen at the hold's next look (5 s), then waited for +rm -f "$tmp/var/lib/omamobile/gnss-bringup-started" "$tmp/run/omamobile-gnss/session"; : > "$tmp/log"; : > "$tmp/unix-late" +echo 'FAKE_STATE=inactive' > "$tmp/modem-state" +( sleep 2; printf 'FAKE_STATE=activating\nFAKE_ENV=OMAMOBILE_MODEM_GNSS=1\n' > "$tmp/modem-state"; sleep 5; printf '@GNSSND\n' > "$tmp/unix-late" ) & +t0=$SECONDS +FAKE_FILE=$tmp/modem-state OMAMOBILE_GNSS_NOTHING_HOLD=6 OMAMOBILE_GNSS_GNSSD_WAIT=30 \ + run_start "$tmp/dt" "$tmp/unix-late" || fail "the modem started during the hold: the start fails" +wait +grep -c 'chroot gnss-slsi start' "$tmp/log" >/dev/null || fail "the modem started during the hold: its gnssd is waited for past the hold" +(( SECONDS - t0 < 15 )) || fail "the modem started during the hold: the start goes on when gnssd listens" unset OMAMOBILE_GNSS_SYSTEMCTL -rm -f "$tmp/var/lib/omamobile/gnss-bringup-started" -echo "ok - a request before gnssd is up waits for it while the modem brings it, and without it holds a moment before giving up" +rm -f "$tmp/var/lib/omamobile/gnss-bringup-started" "$tmp/run/omamobile-gnss/session" +echo "ok - a request before gnssd is up waits for it while the modem brings it, and without it holds, watching for the modem, before giving up" # A marker left by a bring-up that never finished: the 9a skips GNSS, keeps the marker, and holds the # connection first, so GeoClue's reconnects can't fail the socket and --retry's next request finds it listening date -Is > "$tmp/var/lib/omamobile/gnss-bringup-started" @@ -136,44 +186,57 @@ date -Is > "$tmp/var/lib/omamobile/gnss-bringup-started" OMAMOBILE_GNSS_NOTHING_HOLD=2 run_start "$tmp/dt" "$tmp/unix" || fail "a leftover marker: the start fails" (( SECONDS - t0 >= 2 )) || fail "a leftover marker on the 9a: the connection is held before the skip" grep -c 'gnss-slsi start' "$tmp/log" >/dev/null && fail "a leftover marker: gnss-slsi started" +grep -c '^inhibit ' "$tmp/log" >/dev/null && fail "a leftover marker: the sleep inhibitor was taken" [[ -e "$tmp/var/lib/omamobile/gnss-bringup-started" ]] || fail "a leftover marker: the skip keeps it" rm -f "$tmp/var/lib/omamobile/gnss-bringup-started" echo "ok - a leftover marker skips GNSS on the 9a after holding the connection, and stays" -grep -qx 'After=omamobile-tegu-modem.service' vendor/systemd/system/omamobile-gnss.service \ +grep -c -x 'After=omamobile-tegu-modem.service' vendor/systemd/system/omamobile-gnss.service >/dev/null \ || fail "the GNSS stack stops before the 9a's modem unit at shutdown" grep -E '^(Requires|Wants|BindsTo)=.*omamobile-tegu-modem' vendor/systemd/system/omamobile-gnss.service \ && fail "the GNSS stack must not pull the modem in" echo "ok - at shutdown the GNSS stack stops before the 9a's modem, which it never starts" -# The client survives the bridge going first: SIGPIPE ignored for its spawn (inherited across exec), and only for it -awk '/^profile_start\(\)/,/^}/' profiles/gnss-slsi.conf > "$tmp/ps" -grep -n "trap '' PIPE" "$tmp/ps" | head -1 | cut -d: -f1 > "$tmp/ign"; grep -n 'spawn client' "$tmp/ps" | head -1 | cut -d: -f1 > "$tmp/cl" -grep -n 'trap - PIPE' "$tmp/ps" | head -1 | cut -d: -f1 > "$tmp/rst"; grep -n 'spawn hal' "$tmp/ps" | head -1 | cut -d: -f1 > "$tmp/hal" -[[ -s $tmp/ign && -s $tmp/cl && -s $tmp/rst && -s $tmp/hal ]] || fail "the 9a's profile ignores SIGPIPE around the client's spawn" -(( $(<"$tmp/hal") < $(<"$tmp/ign") && $(<"$tmp/ign") < $(<"$tmp/cl") && $(<"$tmp/cl") < $(<"$tmp/rst") )) \ - || fail "SIGPIPE is ignored for the client only, after the HAL's spawn and back to default after it" +# The client survives the bridge going first: SIGPIPE ignored around its spawn (inherited across exec), set +# after the HAL's spawn and back to default after the client's +order=$(awk '/^profile_start\(\)/ {p=1} p && /spawn hal / {print "hal"} p && /^ trap .. PIPE$/ {print "ignore"} + p && /spawn client / && !c++ {print "client"} p && /^ trap - PIPE$/ {print "default"} p && /^}/ {exit}' profiles/gnss-slsi.conf | paste -sd' ') +[[ $order == "hal ignore client default" ]] \ + || fail "the 9a's profile ignores SIGPIPE for the client's spawn only: after the HAL's, default again after it (got: $order)" echo "ok - the 9a's client outlives a bridge that stops first, so the stack's stop stays a clean one" -# The 9a's graceful stop: the client alone first, with the stop-requested file written before its signal, so it -# can stop the receiver through the HAL; the runner takes that exit as a clean stop -sleep 30 & fake=$! +# The 9a's graceful stop: the client alone first, the stop-requested file written before its signal (the +# runner reads it when the client's exit wakes it), so the client can stop the receiver through the HAL mkdir -p "$tmp/run-ps" +F=$tmp/run-ps/stop-requested bash -c 'sleep 30 & s=$!; trap "kill $s; [[ -e \$F ]] && exit 7; exit 9" TERM; wait $s' & fake=$! +sleep 0.3 out=$(STOP_REQUESTED="$tmp/run-ps/stop-requested" FAKE=$fake bash -c ' say() { echo "say: $*"; } - pgrep() { [[ $* == "-f ^/omamobile/bin/omamobile-gnss-client " ]] && echo "$FAKE"; } + pgrep() { [[ $* == "-o -f ^/omamobile/bin/omamobile-gnss-client " ]] && echo "$FAKE"; } source <(awk "/^profile_stop\\(\\)/,/^}/" profiles/gnss-slsi.conf) profile_stop echo "returned"' 2>&1) -grep -qx returned <<<"$out" || fail "profile_stop returns" -[[ -e $tmp/run-ps/stop-requested ]] || fail "profile_stop writes the stop-requested file" +grep -c -x returned <<<"$out" >/dev/null || fail "profile_stop returns" +if kill -0 "$fake" 2>/dev/null; then + kill -KILL "$fake" 2>/dev/null || true + fail "profile_stop sends the client TERM" +fi rc=0; wait "$fake" || rc=$? -(( rc == 143 )) || { kill "$fake" 2>/dev/null; fail "profile_stop sends the client TERM"; } +(( rc != 9 )) || fail "profile_stop writes the stop-requested file before it signals the client" +(( rc == 7 )) || fail "profile_stop ends the client with TERM (its exit: $rc)" out=$(STOP_REQUESTED="$tmp/run-ps/none" bash -c ' say() { :; }; pgrep() { return 1; } source <(awk "/^profile_stop\\(\\)/,/^}/" profiles/gnss-slsi.conf) profile_stop; echo "returned"') [[ $out == returned && ! -e $tmp/run-ps/none ]] || fail "no client: profile_stop writes nothing and returns" -grep -n 'wait -n || true' -A 2 lib/omamobile-vendor-chroot | grep -c '\[\[ -e $STOP_REQUESTED \]\] && stop 0' >/dev/null \ - || fail "the runner takes a requested stop's exit as clean" -grep -q 'rm -f "$NSPID" "$STOP_REQUESTED"' lib/omamobile-vendor-chroot || fail "a new start drops an old stop-requested file" +# ...and the runner's own lines, run: a daemon that exits with the file there ends the profile quietly with +# 0, and without it as before ("a service exited", 1). setsid: its stop signals its whole process group. +awk '/^stop\(\) \{/,/^}/' lib/omamobile-vendor-chroot > "$tmp/runner-stop" +awk '/^ wait -n \|\| true$/ {p=1} p {print} p && /^ stop 1$/ {exit}' lib/omamobile-vendor-chroot > "$tmp/runner-tail" +[[ -s $tmp/runner-stop && $(grep -c . "$tmp/runner-tail") -ge 4 ]] || fail "the runner's stop and supervision lines are where the test reads them" +{ printf 'STOPPING=\nsay() { echo "say: $*"; }\n'; cat "$tmp/runner-stop"; printf 'sleep 30 &\nsleep 0.3 &\n'; cat "$tmp/runner-tail"; } > "$tmp/runner-harness" +rc=0; out=$(STOP_REQUESTED="$tmp/run-ps/stop-requested" setsid --wait bash "$tmp/runner-harness" 2>&1) || rc=$? +[[ $rc == 0 && $out == "say: stopping" ]] || fail "a requested stop: the runner stops the rest quietly with 0 (rc $rc: $out)" +rc=0; out=$(STOP_REQUESTED="$tmp/run-ps/none" setsid --wait bash "$tmp/runner-harness" 2>&1) || rc=$? +[[ $rc == 1 && $out == *"say: a service exited"* ]] || fail "no requested stop: a daemon's exit is still reported and ends with 1 (rc $rc: $out)" +grep -c 'rm -f "$NSPID" "$STOP_REQUESTED"' lib/omamobile-vendor-chroot >/dev/null || fail "a new start drops an old stop-requested file" echo "ok - the 9a's stop ends the client first, through the HAL, and the runner calls that a clean stop" rm -rf "$tmp" @@ -187,8 +250,8 @@ grep -c 'gnss-slsi/data/vendor/gps' vendor/systemd/system/omamobile-gnss-nmea.se # --stop comes before the hang marker, so a leftover marker never skips a stop [[ $(grep -n -- '--stop' lib/omamobile-gnss-start | head -1 | cut -d: -f1) -lt $(grep -n 'elif \[\[ -e \$MARK' lib/omamobile-gnss-start | cut -d: -f1) ]] || fail "--stop before the marker" # A running stack keeps the phone awake (SUSPEND-PLAN 6.1). -grep -qx 'ExecStart=/usr/bin/systemd-inhibit --what=sleep --mode=block "--who=Omarchy Mobile GNSS" "--why=A location session is running" /usr/lib/omamobile-vendor/omamobile-gnss-start' \ - vendor/systemd/system/omamobile-gnss.service || fail "the stack holds a sleep inhibitor while it runs" +grep -c '^INHIBIT=("${OMAMOBILE_GNSS_INHIBIT:-/usr/bin/systemd-inhibit}" --what=sleep --mode=block$' lib/omamobile-gnss-start >/dev/null \ + || fail "the stack holds a sleep inhibitor (block mode) while it runs" # One GeoClue agent, ours (2026-11-02): geoclue's XDG autostart of its demo # agent ran at login, our unit exited as a second instance and stayed # inactive. The mask must carry the generator's escaped name, and our unit diff --git a/packages/omamobile-gnss/vendor/systemd/system/omamobile-gnss.service b/packages/omamobile-gnss/vendor/systemd/system/omamobile-gnss.service index 86bb9d8e8..6eb84f2be 100644 --- a/packages/omamobile-gnss/vendor/systemd/system/omamobile-gnss.service +++ b/packages/omamobile-gnss/vendor/systemd/system/omamobile-gnss.service @@ -7,9 +7,10 @@ [Unit] Description=Omarchy Mobile GNSS (Pixel 7 Pro: BCM4775x, stock lhd and gpsd; Pixel 9a: the modem's Kepler through the stock HAL) After=network-online.target -# The 9a's gnssd runs in the modem's unit: stopped after it at shutdown, a -# session ends before gnssd goes, so a reboot mid-session is a clean stop and -# clears the hang marker. Ordering only; nothing here starts the modem. +# The 9a's gnssd runs in the modem's unit. Ordered after it, this unit stops +# before it at shutdown: a session ends while gnssd is still there, so a +# reboot mid-session is a clean stop and clears the hang marker. Ordering +# only; nothing here starts the modem. After=omamobile-tegu-modem.service StopWhenUnneeded=yes ConditionPathExists=|/usr/lib/omamobile-vendor/gnss/root @@ -18,8 +19,11 @@ ConditionPathExists=|/usr/lib/omamobile-vendor/gnss-slsi/root [Service] # A location session keeps the phone awake: while the stack runs it holds a # logind sleep inhibitor (block mode), which logind and omamobile-sleepd -# honour (device/cheetah/SUSPEND-PLAN.md 6.1). It ends with the stack. -ExecStart=/usr/bin/systemd-inhibit --what=sleep --mode=block "--who=Omarchy Mobile GNSS" "--why=A location session is running" /usr/lib/omamobile-vendor/omamobile-gnss-start +# honour (device/cheetah/SUSPEND-PLAN.md 6.1). It ends with the stack. The +# start takes it itself (systemd-inhibit, as this line did before 0.2.12): +# at once on the 7 Pro, and on the 9a only once a session starts, not while +# it waits for gnssd or holds a client off with the modem down. +ExecStart=/usr/lib/omamobile-vendor/omamobile-gnss-start # Before the stop signal: ask gpsd to end its request, so it saves its # state (gldata.sto) for the next start. Bounded at ~4 s. ExecStop=/usr/lib/omamobile-vendor/omamobile-gnss-start --stop