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 ae2df29eb..e4bc5a064 100755 --- a/packages/omamobile-gnss/lib/omamobile-gnss-start +++ b/packages/omamobile-gnss/lib/omamobile-gnss-start @@ -16,6 +16,34 @@ 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, 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 + 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). @@ -50,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 @@ -61,6 +93,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 @@ -71,7 +107,22 @@ 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 + # 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 + 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" exit 0 fi @@ -96,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/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 1ee6363f6..3d09fe4a1 100644 --- a/packages/omamobile-gnss/profiles/gnss-slsi.conf +++ b/packages/omamobile-gnss/profiles/gnss-slsi.conf @@ -47,14 +47,43 @@ 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 -o -f '^/omamobile/bin/omamobile-gnss-client ') || 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 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 006c3afa7..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,8 +46,11 @@ 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 : > "$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" @@ -92,6 +104,141 @@ 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 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:-}" ;; +esac +EOF +chmod +x "$tmp/systemctl" +export OMAMOBILE_GNSS_SYSTEMCTL=$tmp/systemctl +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=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" +(( 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" +(( 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" +gave_up "gnssd never came" +( sleep 1; printf '@GNSSND\n' > "$tmp/unix-late" ) & +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" "$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" +: > "$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" +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 -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 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, 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() { [[ $* == "-o -f ^/omamobile/bin/omamobile-gnss-client " ]] && echo "$FAKE"; } + source <(awk "/^profile_stop\\(\\)/,/^}/" profiles/gnss-slsi.conf) + profile_stop + echo "returned"' 2>&1) +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 != 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" +# ...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" 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" @@ -103,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 355a6e6fc..6eb84f2be 100644 --- a/packages/omamobile-gnss/vendor/systemd/system/omamobile-gnss.service +++ b/packages/omamobile-gnss/vendor/systemd/system/omamobile-gnss.service @@ -7,6 +7,11 @@ [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. 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 ConditionPathExists=|/usr/lib/omamobile-vendor/gnss-slsi/root @@ -14,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 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