Skip to content

fix(core): move sigaction unsafe out of core into fast_io#4571

Merged
oferchen merged 1 commit into
masterfrom
fix/core-signal-unsafe-out-of-core
May 20, 2026
Merged

fix(core): move sigaction unsafe out of core into fast_io#4571
oferchen merged 1 commit into
masterfrom
fix/core-signal-unsafe-out-of-core

Conversation

@oferchen
Copy link
Copy Markdown
Owner

Summary

  • Hoists the libc::sigaction FFI call out of core::signal::unix and into a new fast_io::signal module that exposes a safe install_signal_handler(signum, handler) API.
  • Removes the module-level #![allow(unsafe_code)] override from core::signal so the core crate's #![deny(unsafe_code)] now covers the signal subtree.
  • Preserves all signal semantics: same four signals (SIGINT, SIGTERM, SIGHUP, SIGPIPE), same handler functions, same SA_RESTART flag, same atomic-flag state machine.

Why

core was the only general-purpose crate left carrying a module-scoped unsafe override. The workspace policy confines unsafe code to a small set of permitted crates (fast_io, metadata, checksums, engine, protocol); fast_io is the long-term home for platform FFI. Moving the eight lines of sigaction setup behind a one-call safe wrapper deletes the override without changing behaviour.

Layout

  • crates/fast_io/src/signal/mod.rs - public SignalHandlerFn alias and re-exports.
  • crates/fast_io/src/signal/unix.rs - the single unsafe block (zero-init sigaction, SA_RESTART, submit). Tested with SIGUSR1 (must install) and -1 (must return EINVAL).
  • crates/fast_io/src/signal/stub.rs - no-op for non-Unix targets.
  • crates/core/src/signal/unix.rs - now calls fast_io::signal::install_signal_handler four times.
  • crates/core/src/signal/mod.rs - module-level #![allow(unsafe_code)] removed; doc comment updated.

Test plan

  • cargo fmt --all -- --check clean.
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings clean.
  • CI: fmt+clippy, nextest (stable), Windows, macOS, Linux musl.
  • Verify core::signal::install_signal_handlers() integration test still passes (no API change).

The `core::signal::unix` module installed Unix signal handlers with a
direct `libc::sigaction` call inside `unsafe { }`, requiring a
module-level `#![allow(unsafe_code)]` override on `core::signal`. That
violates the workspace policy that confines unsafe code to a small set of
permitted crates (`fast_io`, `metadata`, `checksums`, `engine`,
`protocol`).

Hoist the FFI into a new `fast_io::signal` module that exposes a safe
`install_signal_handler(signum, handler)` API. The wrapper zero-initialises
the `sigaction` struct, sets `SA_RESTART`, and submits it; non-Unix
targets compile to a no-op stub. `core::signal::unix` now installs SIGINT,
SIGTERM, SIGHUP, and SIGPIPE through that safe API, and the module-level
unsafe override is removed so `core`'s `#![deny(unsafe_code)]` covers the
signal subtree.

Signal semantics are unchanged: same four signals, same handler
functions, same `SA_RESTART` flag, same atomic-flag state machine.
@github-actions github-actions Bot added the bug Something isn't working label May 20, 2026
@oferchen oferchen merged commit 4d8f668 into master May 20, 2026
55 checks passed
oferchen added a commit that referenced this pull request May 20, 2026
- README status table and Known Limitations now state IOCP is wired
  for the receive-side disk-write pipeline (transfer::disk_commit
  dispatches Writer::Iocp on Windows) in addition to socket transports,
  not just compiled. The stale #1868 issue reference is dropped; the
  read-path extension is tracked under WPG-1.
- README and SECURITY.md unsafe-code inventories reflect PR #4571:
  signal-handler installation lives in fast_io::signal as a safe
  wrapper, core::signal carries no unsafe override, and platform's
  bullet drops "signal handlers" from its description.
- SECURITY.md notes the test-only #[allow(unsafe_code)] on
  embedding's tests::EnvGuard helper so the deny-only list is accurate
  for production code without misrepresenting test scaffolding.
@oferchen oferchen deleted the fix/core-signal-unsafe-out-of-core branch May 20, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant