Fix capture adapter detection on adapters with long iw output #183

Merged
aluminum-ice merged 1 commit from fix-monitor-detect-pipefail into main 2026-11-10 07:09:58 +00:00
Owner

What this PR does

Fixes capture adapter detection for adapters whose iw phy info output is long. iface_monitor_capable piped iw into grep -q. Under the scripts' pipefail, grep exiting at the match left iw's later writes to fail on SIGPIPE (141). So a monitor-capable adapter (seen on a tri-band MT7921U) read as not capable, kestrel capture status showed "adapter: none detected", and enabling capture was refused. The output is now captured before it is matched, as the note above the Bluetooth helpers in common.sh already asks. The same change goes into the other pipes into an early-exiting reader on the capture, plugin-enable and update paths (ethtool | awk …exit in capture_resolve_iface, plugin_has_network_cap, and the update's link count), for consistency.

Thanks to a community member who found this on hardware and sent in the fix through the GitHub mirror.

Checklist

  • Lint passes — make lint (ansible --syntax-check, yamllint, shellcheck --severity=error, and the real-data check). The Lint workflow runs this on the PR.
  • Tests pass — make test (the kestrel_pi pytest suite and the real-data check's tests). The Test workflow runs this on the PR.
  • Nothing real: no secrets, no personal information, no real data. This is a public repository. The diff contains no real account passwords or hashes, Wi-Fi passphrases, private keys, API tokens, .env files, real names, personal emails, device serials, and no real captured or device data: SSIDs, MAC addresses, GPS coordinates, capture files, diagnostics bundles, logs, or screenshots of a real device — placeholders only. The real-data check catches MACs, emails, keys and capture files; real SSIDs, coordinates and screenshots are on you.
  • Consent gates intact. Capture and network plugins still ship disabled, enabling them still takes the authorized-use acknowledgment (never pre-ticked or given by code), and the capture whitelist is still enforced.
  • Docs updated in the same PR, if this changes something an operator sees or configures: nothing an operator configures changes.
  • Commit messages are short and imperative.

Release impact

  • App-layer-safe — changes only files the in-place update engine carries: the kestrel_pi package, plugins/*.py, systemd units, the journald drop-in, a lib script already in the engine's LIB_SCRIPTS, or the CLI.
  • Reflash-class — touches a build input the engine does not carry onto a running device: apt or pip packages, boot options / config.txt / cmdline, kernel modules, the base image or partition size, builder/config.json, builder/config.yml, the Makefile, the Release workflow (.forgejo/workflows/main.yml), a shipped config default (config.toml / default.conf), or a brand-new lib script.

common.sh is in the engine's LIB_SCRIPTS, and kestrel.sh is the CLI.

Notes for review

  • Checked locally with stub iw/ethtool under set -euo pipefail. With 3,000 lines of output after the match, the old helper found the adapter 0 times in 200 and the new one 100 times in 100. An adapter without monitor mode still reads as not capable, the built-in chip is still skipped, and capture_resolve_iface auto returns the right interface.
  • plugin_has_network_cap now matches on captured output. A spurious 141 can no longer read as "no network capability", so the acknowledgment prompt is never skipped that way.
  • make test locally: 1715 passed, 5 failed in tests/test_web.py. The same 5 fail on main with this host's Werkzeug 3.1.9, and nothing in this PR touches Python, so the box is left for the Test workflow.
  • This needs a first test on hardware with a tri-band USB adapter. It's worth a checklist item in the next beta.

🤖 Generated with Claude Code

## What this PR does Fixes capture adapter detection for adapters whose `iw phy info` output is long. `iface_monitor_capable` piped `iw` into `grep -q`. Under the scripts' `pipefail`, grep exiting at the match left `iw`'s later writes to fail on SIGPIPE (141). So a monitor-capable adapter (seen on a tri-band MT7921U) read as not capable, `kestrel capture status` showed "adapter: none detected", and enabling capture was refused. The output is now captured before it is matched, as the note above the Bluetooth helpers in `common.sh` already asks. The same change goes into the other pipes into an early-exiting reader on the capture, plugin-enable and update paths (`ethtool | awk …exit` in `capture_resolve_iface`, `plugin_has_network_cap`, and the update's link count), for consistency. Thanks to a community member who found this on hardware and sent in the fix through the GitHub mirror. ## Checklist - [x] **Lint passes** — `make lint` (ansible `--syntax-check`, `yamllint`, `shellcheck --severity=error`, and the real-data check). The **Lint** workflow runs this on the PR. - [ ] **Tests pass** — `make test` (the `kestrel_pi` pytest suite and the real-data check's tests). The **Test** workflow runs this on the PR. - [x] **Nothing real: no secrets, no personal information, no real data.** This is a public repository. The diff contains no real account passwords or hashes, Wi-Fi passphrases, private keys, API tokens, `.env` files, real names, personal emails, device serials, and no real captured or device data: SSIDs, MAC addresses, GPS coordinates, capture files, diagnostics bundles, logs, or screenshots of a real device — placeholders only. The real-data check catches MACs, emails, keys and capture files; real SSIDs, coordinates and screenshots are on you. - [x] **Consent gates intact.** Capture and network plugins still ship disabled, enabling them still takes the authorized-use acknowledgment (never pre-ticked or given by code), and the capture whitelist is still enforced. - [x] **Docs updated in the same PR**, if this changes something an operator sees or configures: nothing an operator configures changes. - [x] Commit messages are short and imperative. ## Release impact - [x] **App-layer-safe** — changes only files the in-place update engine carries: the `kestrel_pi` package, `plugins/*.py`, systemd units, the journald drop-in, a lib script already in the engine's `LIB_SCRIPTS`, or the CLI. - [ ] **Reflash-class** — touches a build input the engine does not carry onto a running device: apt or pip packages, boot options / `config.txt` / `cmdline`, kernel modules, the base image or partition size, `builder/config.json`, `builder/config.yml`, the `Makefile`, the Release workflow (`.forgejo/workflows/main.yml`), a shipped config default (`config.toml` / `default.conf`), or a brand-new lib script. `common.sh` is in the engine's `LIB_SCRIPTS`, and `kestrel.sh` is the CLI. ## Notes for review - Checked locally with stub `iw`/`ethtool` under `set -euo pipefail`. With 3,000 lines of output after the match, the old helper found the adapter 0 times in 200 and the new one 100 times in 100. An adapter without monitor mode still reads as not capable, the built-in chip is still skipped, and `capture_resolve_iface auto` returns the right interface. - `plugin_has_network_cap` now matches on captured output. A spurious 141 can no longer read as "no `network` capability", so the acknowledgment prompt is never skipped that way. - `make test` locally: 1715 passed, 5 failed in `tests/test_web.py`. The same 5 fail on `main` with this host's Werkzeug 3.1.9, and nothing in this PR touches Python, so the box is left for the Test workflow. - This needs a first test on hardware with a tri-band USB adapter. It's worth a checklist item in the next beta. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Fix capture adapter detection on adapters with long iw output
All checks were successful
Lint / lint (push) Successful in 45s
Test / test (push) Successful in 1m13s
Lint / lint (pull_request) Successful in 30s
Test / test (pull_request) Successful in 58s
c4bc4da9e2
iface_monitor_capable piped `iw phy info` into `grep -q`. Under the
scripts' pipefail, grep exiting at the match leaves iw's later writes to
fail on SIGPIPE (141), so an adapter with long output, such as a
tri-band MT7921U, read as not monitor-capable and capture found no
adapter. Capture the output first and match on it, as the other helpers
do. The same change goes into the other pipes into an early-exiting
reader in the capture, plugin-enable and update paths, for consistency.

Thanks to a community member who sent in the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aluminum-ice deleted branch fix-monitor-detect-pipefail 2026-11-10 07:09:58 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aluminum-ice/kestrel!183
No description provided.