Skip to content

bin/omamobile, tools, rootfs: no pipe into grep -q under pipefail - #587

Merged
derekross merged 3 commits into
derekross:mainfrom
only21mil:build/tools-no-grep-q-pipes
Nov 10, 2026
Merged

derekross merged 3 commits into
derekross:mainfrom
only21mil:build/tools-no-grep-q-pipes

Conversation

@only21mil

@only21mil only21mil commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The follow-up to #575, which fixed the test scripts: the same pattern in the laptop-side scripts that set pipefail, with bin/omamobile's adb get-state | grep -q device among them. grep -q exits at the first match, a writer that is still writing gets SIGPIPE, and pipefail fails the pipeline (AGENTS.md §4, Userspace; LESSONS L-15). Each site now uses grep -c … >/dev/null, with the same pattern, flags and truth value (!, && and || kept).

site could it race
bin/omamobile:1125, :1141 (adb get-state) no, one line
rootfs/build-inside:201 (user-account check) no, but on a SIGPIPE it would have skipped the die
tools/extract-{fingerprint-vendor,vendor-chroot,vendor-firmware} (android-info.txt), extract-fingerprint-vendor:342 (head -c 64) no, short writers
tools/fingerprint-capture:128 (since_start) yes: sed prints the whole log after the end line; the old check missed it 100 of 100 times on a 50k-line log, and the step ran to its timeout
tools/lib/signing.sh:39, :43 (trusted and revoked) no, but on a SIGPIPE a revoked key would have passed

Race harness, under pipefail, with a writer that prints the match and then 200k more lines, 200 runs per form (if, &&, || die, if !, revoked): old 0/200, new 200/200. With no match, both forms agree.

tests/grep-q-pipes now also scans pipefail scripts in bin/, tools/ and rootfs/, plus tools/lib (sourced by pipefail scripts), and skips comment lines. A stray pipe in tools/lib/signing.sh or tools/extract-vendor-chroot fails it and names the line.

Not changed:

  • packages/ (omamobile-boot-success ×3, omamobile-usb-rescue ×4, omamobile-wait-bluetooth, omamobile-remote, omamobile-keys, QuickSettings.qml, Omarchy patches 0006/0007/0022, owl-widgets): the phone-side runtime files remain unchanged; touching them would require package version bumps and a phone smoke report. packages/omamobile-device-husky/test/all and packages/omamobile-modem/test/nv-overlay are host tests; the latter remains out until tests: intermittent Broken pipe in omamobile-modem NV-overlay tests on Omarchy #457.
  • initramfs/init:292: it's in every boot image and safety-critical. It's busybox sh, which has no pipefail, so it can't race.
  • The command strings that acpm-stage, aoc-stage, fingerprint-capture, husky-deadman and wifi-w1-capture send through tools/phone-ssh: they run in the phone's shell, which has no pipefail. The guard leaves these five files out by path, with that reason in its comment.
  • device/dodge/desktop/setup-stock:64: it runs on the dodge phone and its writer prints one or two lines.

Device and build

  • Phone: none: laptop-side tools only
  • Kernel release (uname -r): n/a
  • Packages changed, with versions: none

Checks (no phone needed)

  • tools/pr-check origin/main passes
  • tests/all passes (490 ok, 0 not ok)
  • tests/packages: no package touched
  • Each changed package has its version bumped, and the new version is in the commit subject (no package changed)
  • Commits have area prefixes and bodies that say why; any AI help is a Co-Authored-By: or Assisted-by: trailer, never a Signed-off-by:

On the phone

  • I ran this on my own phone, booted into this build: not applicable, nothing that runs on the phone changes
  • Runbook steps passed (plan, step, result): n/a
  • What I did not test: fingerprint-capture and bin/omamobile fastboot against a real phone; the race was shown with the same command shapes on the laptop
  • Nothing in this change writes outside slot B and userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)
tools/phone-smoke report

Not applicable: laptop-side tools only (CONTRIBUTING.md §6.5).

Generated with Claude Opus 5.5 in T3 Code Nightly

The follow-up to derekross#575, which fixed the test scripts: the same pattern
in the laptop-side scripts that set pipefail. grep -q exits at the first
match, a writer still writing gets SIGPIPE, and pipefail fails the
pipeline (AGENTS.md section 4, Userspace). Each site now uses
grep -c ... >/dev/null, which reads all its input, with the same
pattern, flags and truth value.

The one that loses in practice is tools/fingerprint-capture's wait
loop: sed prints the whole log from the step's start, and with the end
line early in a verbose kmsg stream the old check never saw it and the
step ran to its timeout. The others have short writers (adb get-state,
android-info.txt, 64 bytes of the TA, the keyring, the image's
passwd) that fit the pipe buffer before grep exits; they change so
that no script keeps the pattern. Two of them failed open:
build-inside's user-account check and signing.sh's revoked-key check
would have passed on a SIGPIPE.

tests/grep-q-pipes now scans bin/, tools/ and rootfs/ as well, plus
tools/lib (sourced by pipefail scripts), and skips comment lines. It
leaves out five stage tools whose remaining hits are command strings
that tools/phone-ssh runs in the phone's shell, which has no pipefail.
Nothing under packages/ or initramfs/ changes.

Tested: the race harness (old 0/200, new 200/200 per form; the
fingerprint-capture loop old 0/100, new 100/100), tests/grep-q-pipes
with an injected pipe (fails, names the line) and a commented one
(passes), tools/pr-check, tests/all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
derekross and others added 2 commits November 9, 2026 20:32
…y held

The scan's 'packages/*/test' pathspec matched no file, so no package
test was ever scanned (91 scripts). With 'packages/*/test/*' it reads
164, and found two pipes into grep -q that landed since: device-husky's
speaker_protection check (derekross#453) and omamobile-waydroid's render-node
check (derekross#541). Both now read the whole pipe.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@derekross
derekross merged commit 0c2c737 into derekross:main Nov 10, 2026
2 checks passed
@derekross

Copy link
Copy Markdown
Owner

Thank you, Victor. I went through the ten sites one by one: each keeps its pattern, its flags (-E, -a, -x) and its truth value, and the two that failed open (the user-account check in build-inside and the revoked-key check in signing.sh) now fail closed. I reproduced the race with a writer that prints the match and then 200000 lines: grep -q was true 0 times in 100, grep -c … >/dev/null 100 in 100. bin/omamobile only changes inside cmd_fastboot, so nothing about images, flash or push moves.

One thing I found while feeding the scan a known failure, and it is ours as much as yours, since I missed it on #575: the pathspec 'packages/*/test' matches no file. A git pathspec with a wildcard has to match the whole path, so it needs to be 'packages/*/test/*':

git grep -l 'set -[a-z]*o pipefail' -- 'packages/*/test'   | wc -l    # 0
git grep -l 'set -[a-z]*o pipefail' -- 'packages/*/test/*' | wc -l    # 72

So tests/grep-q-pipes has only ever scanned tests/ (and, with this PR, bin/, tools/ and rootfs/): a stray x | grep -q y appended to packages/libfprint/test/run passes. With the pathspec fixed the scan covers 163 scripts instead of 91, and it finds one line that came in after #575, packages/omamobile-device-husky/test/all:169 (! grep -hv … | grep -q 'speaker_protection' || fail, the form that passes on a SIGPIPE).

I've pushed a small commit on top with the pathspec, that husky line as grep -c 'speaker_protection' >/dev/null, and a second hit the fixed scan then found in omamobile-waydroid's test/all (from #541, merged today). With it the scan passes on 164 scripts and both packages' test/all still passes. Merging with that.

For a later PR, if you like: omamobile-boot-success on the 7 Pro, 7a and 6 Pro pipes omamobile-bootctl dump through sed into grep -q under pipefail. The writer is a few lines, so it can't race, but it decides whether the slot is marked again, so I'd like it converted with the package bumps and a boot, as you said.

@only21mil

only21mil commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Note

🤖 Opus 5.5 replying on behalf of Victor.

Two follow-ups from this one:

  • tests/grep-q-pipes: fail when a scan pathspec matches nothing #597 makes tests/grep-q-pipes fail with the pathspec's name if one of its scan pathspecs ever matches no pipefail script again; with 'packages/*/test' put back it now gives not ok - the pathspec 'packages/*/test' matches a pipefail script.
  • omamobile-boot-success's marked check on the 7 Pro, 7a and 6 Pro is converted on a branch, only21mil:build/boot-success-no-grep-q at 5f1c252 (device-cheetah 0.1.49, -lynx 0.2.3, -raven 0.1.34), with the old and new forms agreeing in every case of a stubbed truth table (marked, unmarked, only slot a marked, a failing dump, empty output, a failing sed). It isn't opened yet because it hasn't booted. Could you run a boot and tools/phone-smoke on each of those phones with it installed, and check the journalctl -b -u omamobile-boot-success line? I'll open it with your reports as its phone check.

derekross added a commit to azazelpy/omarchy-mobile that referenced this pull request Nov 10, 2026
Three checks in the new test piped into grep -q, which tests/grep-q-pipes
(derekross#587) refuses under pipefail: grep -q exits early and the writer's
SIGPIPE fails the pipeline. They read a count or compare the first line
now; what they check is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
derekross pushed a commit that referenced this pull request Nov 10, 2026
…dresses across boots (#510)

The USB gadget's two MAC addresses were random at every boot, so the
laptop saw a new network card each time and its connection profile for
the phone never stuck.

omamobile-usb-mac.service now makes one locally administered pair on the
first boot, saves it under /var/lib/omamobile, and puts the same pair on
the gadget at every later boot, before the network is configured. The
addresses are random, never derived from a serial number or any other
identifier of the phone, and never logged.

Changing the addresses means taking the gadget apart, and USB is the only
link, so the step is guarded: a marker is written while the gadget is
apart, anything that fails puts the gadget back together, and a boot that
finds the marker (the last try hung) stands aside and leaves the kernel's
temporary pair in place.

Tested on a Pixel 7 Pro (7.3.0-rc6-omamobile-push1-gbcc4a92ca2e0), the
addresses compared by checksum only:
- first boot: a pair is made and saved;
- second boot: the same pair;
- a boot with the marker placed by hand: the unit stands aside, the
  marker is removed, the saved file is unchanged;
- the next boot: the saved pair is back;
- tools/phone-smoke passes, and the modem is back after every reboot.

The merge also brings the branch up to main, sets the version to 0.1.49
and rewrites three test lines that piped into grep -q (tests/grep-q-pipes,
#587).

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
den-kloot added a commit to den-kloot/omarchy-mobile that referenced this pull request Nov 10, 2026
…de fake tells arguments from stdin

Review of derekross#539. tests/grep-q-pipes (derekross#587) refuses a pipe into grep -q in a
script that sets pipefail: grep -q exits at the first match, the writer can
get SIGPIPE, and pipefail then fails the pipeline at random.
test/hotspot-panel.sh had eleven; they now use grep -c ... >/dev/null,
which reads all its input.

The fake qrencode logged its arguments and its stdin on one line, so the
check that the WIFI: string goes to qrencode on stdin passed either way. It
now writes "qrencode args:" and "qrencode stdin:" lines, and the test checks
that the string arrives on stdin, that the arguments are only the options,
and that the string is never an argument (it would show in
/proc/*/cmdline). With the script changed to pass the string as an
argument, the old test still passed and the new one fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…rekross#587)

* bin/omamobile, tools, rootfs: no pipe into grep -q under pipefail

The follow-up to derekross#575, which fixed the test scripts: the same pattern
in the laptop-side scripts that set pipefail. grep -q exits at the first
match, a writer still writing gets SIGPIPE, and pipefail fails the
pipeline (AGENTS.md section 4, Userspace). Each site now uses
grep -c ... >/dev/null, which reads all its input, with the same
pattern, flags and truth value.

The one that loses in practice is tools/fingerprint-capture's wait
loop: sed prints the whole log from the step's start, and with the end
line early in a verbose kmsg stream the old check never saw it and the
step ran to its timeout. The others have short writers (adb get-state,
android-info.txt, 64 bytes of the TA, the keyring, the image's
passwd) that fit the pipe buffer before grep exits; they change so
that no script keeps the pattern. Two of them failed open:
build-inside's user-account check and signing.sh's revoked-key check
would have passed on a SIGPIPE.

tests/grep-q-pipes now scans bin/, tools/ and rootfs/ as well, plus
tools/lib (sourced by pipefail scripts), and skips comment lines. It
leaves out five stage tools whose remaining hits are command strings
that tools/phone-ssh runs in the phone's shell, which has no pipefail.
Nothing under packages/ or initramfs/ changes.

Tested: the race harness (old 0/200, new 200/200 per form; the
fingerprint-capture loop old 0/100, new 100/100), tests/grep-q-pipes
with an injected pipe (fails, names the line) and a commented one
(passes), tools/pr-check, tests/all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* tests/grep-q-pipes: scan the package tests too, and the two pipes they held

The scan's 'packages/*/test' pathspec matched no file, so no package
test was ever scanned (91 scripts). With 'packages/*/test/*' it reads
164, and found two pipes into grep -q that landed since: device-husky's
speaker_protection check (derekross#453) and omamobile-waydroid's render-node
check (derekross#541). Both now read the whole pipe.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Derek Ross <derekross@gmail.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…dresses across boots (derekross#510)

The USB gadget's two MAC addresses were random at every boot, so the
laptop saw a new network card each time and its connection profile for
the phone never stuck.

omamobile-usb-mac.service now makes one locally administered pair on the
first boot, saves it under /var/lib/omamobile, and puts the same pair on
the gadget at every later boot, before the network is configured. The
addresses are random, never derived from a serial number or any other
identifier of the phone, and never logged.

Changing the addresses means taking the gadget apart, and USB is the only
link, so the step is guarded: a marker is written while the gadget is
apart, anything that fails puts the gadget back together, and a boot that
finds the marker (the last try hung) stands aside and leaves the kernel's
temporary pair in place.

Tested on a Pixel 7 Pro (7.3.0-rc6-omamobile-push1-gbcc4a92ca2e0), the
addresses compared by checksum only:
- first boot: a pair is made and saved;
- second boot: the same pair;
- a boot with the marker placed by hand: the unit stands aside, the
  marker is removed, the saved file is unchanged;
- the next boot: the saved pair is back;
- tools/phone-smoke passes, and the modem is back after every reboot.

The merge also brings the branch up to main, sets the version to 0.1.49
and rewrites three test lines that piped into grep -q (tests/grep-q-pipes,
derekross#587).

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants