Stop AngryOxide cleanly with SIGINT #126

Merged
aluminum-ice merged 1 commit from fix/angryoxide-clean-stop into main 2026-10-31 08:05:11 +00:00
Owner

What this PR does

Stops AngryOxide the way it expects to be stopped, so it shuts down cleanly instead of being killed mid-write. Found by the 1.0.11-beta.2 check (#125, item 5.4: two kismet-journal files left in the run folder after capture stopped).

The cause. In headless mode (how Kestrel runs it), AngryOxide's only signal handler is its Ctrl-C handler, for SIGINT. On it, AngryOxide restores the adapter's MAC, closes its capture file, and has its database writer flush and commit what's queued (up to 2 s, the v0.9.4 batching). The capture service stopped it with SIGTERM: systemd's default stop signals every process in the unit, and the launcher's trap, agent relaunches and run-folder rolls all used kill -TERM. That killed AngryOxide outright. Under v0.9.3's one-row commits a journal only existed for an instant; with batched writes a transaction is usually open, so the kill left one behind.

  • stop_ao in capture-launch.sh: SIGINT, wait up to 10 s (PWN_AO_STOP_SECONDS), then SIGKILL, logged. It's used for an agent relaunch, a roll, and a stop; the stop trap sends SIGINT and the supervisor loop waits through stop_ao.
  • AngryOxide starts with SIGINT reset (env --default-signal=INT, coreutils 8.31+, bookworm has 9.1). A command started with & from a non-interactive script inherits SIGINT ignored. AngryOxide's Rust handler most likely overrides that, but this doesn't depend on it.
  • kestrel-capture.service: KillMode=mixed, so systemd's SIGTERM reaches only the launcher, and anything left after it exits is killed; TimeoutStopSec=30 covers the clean stop.
  • The launcher's cleanup now waits for the collector after signalling it.

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: the README package table, the relevant page under docs/, and the on-device operator guide (GUIDE_MD in kestrel_pi/userguide.py) where it applies.
  • 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, .forgejo/workflows/, a shipped config default (config.toml / default.conf), or a brand-new lib script.

Notes for review

  • For 1.0.11-beta.3. App-layer: capture-launch and the unit are files the updater already installs. No build input changes, so the stable release's floor stays at beta.2.

  • Tests (test_capture_launch.py), with stop_ao run in bash against fake processes started the way the launcher starts AngryOxide:

    • a process that exits on SIGINT gets SIGINT and is waited for, not killed;
    • one that ignores SIGINT is killed after the bound, and the kill is logged;
    • the launcher never sends AngryOxide SIGTERM, and starts it with SIGINT reset;
    • the unit has KillMode=mixed and a stop timeout.

    Writing them also showed the inherited-ignore problem: a bash fake started with & couldn't trap SIGINT until started through env --default-signal=INT.

  • On the device (beta 3's check): stop capture and confirm no kismet-journal is left, and that the journal shows AngryOxide's clean exit rather than "didn't stop within 10s".

  • make lint is clean; the launcher tests pass (12).

🤖 Generated with Claude Code

## What this PR does Stops AngryOxide the way it expects to be stopped, so it shuts down cleanly instead of being killed mid-write. Found by the 1.0.11-beta.2 check (#125, item 5.4: two `kismet-journal` files left in the run folder after capture stopped). **The cause.** In headless mode (how Kestrel runs it), AngryOxide's only signal handler is its Ctrl-C handler, for SIGINT. On it, AngryOxide restores the adapter's MAC, closes its capture file, and has its database writer flush and commit what's queued (up to 2 s, the v0.9.4 batching). The capture service stopped it with **SIGTERM**: systemd's default stop signals every process in the unit, and the launcher's trap, agent relaunches and run-folder rolls all used `kill -TERM`. That killed AngryOxide outright. Under v0.9.3's one-row commits a journal only existed for an instant; with batched writes a transaction is usually open, so the kill left one behind. - **`stop_ao`** in `capture-launch.sh`: SIGINT, wait up to 10 s (`PWN_AO_STOP_SECONDS`), then SIGKILL, logged. It's used for an agent relaunch, a roll, and a stop; the stop trap sends SIGINT and the supervisor loop waits through `stop_ao`. - **AngryOxide starts with SIGINT reset** (`env --default-signal=INT`, coreutils 8.31+, bookworm has 9.1). A command started with `&` from a non-interactive script inherits SIGINT *ignored*. AngryOxide's Rust handler most likely overrides that, but this doesn't depend on it. - **`kestrel-capture.service`**: `KillMode=mixed`, so systemd's SIGTERM reaches only the launcher, and anything left after it exits is killed; `TimeoutStopSec=30` covers the clean stop. - **The launcher's cleanup** now waits for the collector after signalling it. ## 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. - [x] **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: the README package table, the relevant page under `docs/`, and the on-device operator guide (`GUIDE_MD` in `kestrel_pi/userguide.py`) where it applies. - [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`, `.forgejo/workflows/`, a shipped config default (`config.toml` / `default.conf`), or a brand-new lib script. ## Notes for review - For **1.0.11-beta.3**. App-layer: `capture-launch` and the unit are files the updater already installs. No build input changes, so the stable release's floor stays at beta.2. - **Tests** (`test_capture_launch.py`), with `stop_ao` run in bash against fake processes started the way the launcher starts AngryOxide: - a process that exits on SIGINT gets SIGINT and is waited for, not killed; - one that ignores SIGINT is killed after the bound, and the kill is logged; - the launcher never sends AngryOxide SIGTERM, and starts it with SIGINT reset; - the unit has `KillMode=mixed` and a stop timeout. Writing them also showed the inherited-ignore problem: a bash fake started with `&` couldn't trap SIGINT until started through `env --default-signal=INT`. - **On the device** (beta 3's check): stop capture and confirm no `kismet-journal` is left, and that the journal shows AngryOxide's clean exit rather than "didn't stop within 10s". - `make lint` is clean; the launcher tests pass (12). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Stop AngryOxide cleanly with SIGINT
All checks were successful
Test / test (pull_request) Successful in 29s
Lint / lint (pull_request) Successful in 35s
Test / test (push) Successful in 29s
Lint / lint (push) Successful in 36s
9203e23aa1
AngryOxide shuts down cleanly only on SIGINT (its headless Ctrl-C
handler): it restores the adapter's MAC, closes its capture file and
flushes and commits its database. The capture service stopped it with
SIGTERM, which killed it mid-write and, with batched database writes,
usually left a kismet-journal behind. Ask with SIGINT on stop, relaunch
and roll, wait up to 10 s, then kill; start it with SIGINT reset; and
have systemd signal only the launcher (KillMode=mixed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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!126
No description provided.