Repository navigation
fix(server): avoid renameat2 SIGSYS on aarch64 Android (Termux) - #353
Conversation
`cook server` crashed with "Bad system call" when saving recipes on
aarch64 Android (e.g. Termux on a Samsung S8). Reading worked; only
editing failed.
Root cause: the save path writes a temp file then calls
`tokio::fs::rename()`. On aarch64 the kernel exposes no legacy
`rename`/`renameat` syscall, so libc implements `rename()` via
`renameat2`, which Android's (and especially Samsung's) seccomp filter
blocks with SIGSYS. SIGSYS is a fatal signal, not an `Err`, so the
failure can't be caught — the syscall must be avoided entirely.
Add `server::fs_atomic::rename_replace{,_async}`: an atomic rename on
capable platforms, falling back to copy + remove on Android (uses only
permitted syscalls; non-atomic but the only option when renameat2 is
forbidden). Route all three rename sites through it — recipe save,
shopping-list compaction, and legacy migration share the root cause.
Fixes #349
|
Code Review: fix(server) — avoid renameat2 SIGSYS on aarch64 Android Overview This PR fixes a crash on aarch64 Android (Termux) where cook server receives SIGSYS when editing recipes. The root cause analysis is accurate: aarch64 Linux has no legacy rename/renameat syscalls, so libc routes rename() through renameat2, which Android seccomp (especially Samsung vendor policies) blocks — killing the process with a fatal signal before any Rust error handler can run. The fix introduces a new server::fs_atomic module and routes all three rename call sites through it. Strengths
Issues and Suggestions Minor: Use super::fs_atomic inside the server module Both handlers/recipes.rs and shopping_list_store.rs are already inside crate::server, so crate::server::fs_atomic::rename_replace(...) can be shortened to super::fs_atomic::rename_replace(...), or simply add a use import at the top of each file. The full crate:: path works but is unusual for in-module references. Minor: Inconsistent parameter style between sync and async variants rename_replace takes &Path (ergonomic), while rename_replace_async takes Utf8PathBuf by value (needed for spawn_blocking's 'static bound). This forces call sites that already own a Utf8PathBuf — like recipes.rs — to .clone() unnecessarily. The async variant could instead take &Utf8Path and clone internally, pushing the allocation inside the function rather than at every call site. This is a nit — the current approach is entirely correct. Worth noting: Partial-success edge case in the Android copy+remove path In rename_replace on Android, if copy succeeds but remove_file fails, the function returns Err even though the destination was already written correctly. The outer error handlers call remove_file(&tmp_path) on failure — which is still correct since the source file is still present — but an Err is propagated to the caller despite the write having fully succeeded from a data-safety perspective. This is extremely unlikely in practice and inherent to the non-atomic workaround, but a brief comment would help future maintainers understand the subtle behavior. MSRV: io::Error::other requires Rust 1.74 io::Error::other() was stabilized in November 2023. If the project pins a lower MSRV via rust-version in Cargo.toml, this will fail on older toolchains. Worth a quick check — if no MSRV is pinned, this is a non-issue. Test gap (acknowledged, unavoidable) The tests cover the contract on the host but cannot reproduce SIGSYS. One cheap addition: a test that verifies rename_replace propagates Err when from does not exist, guarding the error-path code. Summary This is a well-researched, correctly scoped fix with clear documentation and appropriate tests given the platform constraints. All items above are minor nits or edge-case observations — none are blockers. The PR is ready to merge, ideally with confirmation from a user on an affected aarch64 Android device as noted in the description. Verdict: Approve with minor suggestions. |
Review — fix(server): avoid renameat2 SIGSYS on aarch64 Android (Termux)Root-cause analysis and fix logic are sound. The module-level docs clearly explain the SIGSYS mechanism, and the three call-site changes are consistent. Tests cover the happy-path contract well for host builds. Critical concern: The release pipeline ( Possible fixes:
The second option (widen the cfg) is the lowest-friction path that actually fixes Termux users on the current release binary. Other notes
The fix is logically correct and will help users who build from source with an Android target triple. The main ask before merging is resolving the cfg scope so prebuilt release binaries actually benefit. |
cookcli 0.31.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## [0.31.0](cooklang/cookcli@v0.30.0...v0.31.0) (2026-06-09) ### Features * **build:** generate sitemap.xml with `cook build web --sitemap` ([#351](cooklang/cookcli#351)) ([6db127a](cooklang/cookcli@6db127a)) ### Bug Fixes * **server:** avoid renameat2 SIGSYS on aarch64 Android (Termux) ([#353](cooklang/cookcli#353)) ([46950ab](cooklang/cookcli@46950ab)), closes [#349](https://github.com/cooklang/cookcli/issues/349)</pre> <p>View the full release notes at <a href="https://github.com/cooklang/cookcli/releases/tag/v0.31.0">https://github.com/cooklang/cookcli/releases/tag/v0.31.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!11090
Problem
Fixes #349.
cook servercrashes with "Bad system call" when saving/editing a recipe on aarch64 Android (reported on Termux on a Samsung S8). Reading recipes works fine — only editing fails.Root cause
"Bad system call" is SIGSYS, raised by Android's seccomp filter when a process makes a blocked syscall (Samsung devices ship especially strict policies).
The save path (
recipe_save) writes a temp file and then callstokio::fs::rename(). On aarch64 the kernel exposes no legacyrename/renameatsyscall, so libc implementsrename()viarenameat2— which Android/Samsung seccomp blocks → SIGSYS → the server process is killed.rename).Err, so.map_err()never runs — the syscall must be avoided, not handled.Fix
New
server::fs_atomicmodule withrename_replace/rename_replace_async:renameas before (keeps crash-safety on servers/desktops).copy+remove_file, which use only permitted syscalls (openat/read/write/unlinkat). Non-atomic, but the only option whenrenameat2is forbidden.All three
fs::renamesites are routed through it — recipe save, shopping-list compaction, and legacy shopping-list migration — since they share the same root cause and would all crash on the affected device.Verification
cargo fmt --checkcleancargo clippyclean on both host andaarch64-linux-androidtargetscargo check --target aarch64-linux-androidcompiles the Android branchcargo test— all pass, incl. 3 new unit tests for the helperLimitation
The unit tests cover the helper's contract on the host but cannot reproduce the actual SIGSYS (that needs aarch64 Android seccomp, unavailable in CI). The fix rests on the root-cause analysis plus confirming the Android branch compiles and avoids
renameat2by construction. Confirmation from a user on an affected device before release would be ideal.