Skip to content

feat: add daemon signal handling (SIGHUP/SIGTERM/SIGPIPE) - #2376

Merged
oferchen merged 1 commit into
masterfrom
feature/daemon-signal-handling
Feb 21, 2026
Merged

oferchen merged 1 commit into
masterfrom
feature/daemon-signal-handling

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Register Unix signal handlers at daemon startup using signal-hook crate (safe API, no unsafe blocks)
  • SIGPIPE: Captured into a never-checked flag, replacing default termination so broken-pipe errors surface as io::Error instead of killing the daemon
  • SIGHUP: Sets reload_config AtomicBool flag checked each accept-loop iteration, logging the event and notifying systemd
  • SIGTERM/SIGINT: Sets shutdown AtomicBool flag that breaks the accept loop, allowing existing worker threads to drain naturally
  • All signal code gated with #[cfg(unix)] with no-op stubs for non-Unix platforms
  • Both single-listener and dual-stack paths now use non-blocking accept with periodic signal flag checks

Test plan

  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings passes
  • cargo fmt --package daemon -- --check passes
  • cargo nextest run --package daemon --all-features passes (734 tests)
  • New unit tests for SignalFlags default values, set/check operations, and handler registration
  • CI: fmt+clippy, nextest (stable), Windows, macOS, Linux musl

Register Unix signal handlers at daemon startup so the server loop
responds correctly to process signals, matching upstream rsync behavior:

- SIGPIPE: Captured into a never-checked flag, replacing the default
  termination action so broken-pipe errors surface as io::Error instead
  of killing the daemon process.
- SIGHUP: Sets a reload_config AtomicBool flag checked each iteration
  of the accept loop, logging the event and notifying systemd.
- SIGTERM/SIGINT: Sets a shutdown AtomicBool flag that breaks out of
  the accept loop, allowing existing worker threads to drain naturally.

Uses signal-hook crate (safe API only, no unsafe blocks) gated behind
cfg(unix) with no-op stubs for non-Unix platforms. Both single-listener
and dual-stack accept loops now use non-blocking accept with periodic
signal flag checks instead of indefinite blocking.
@github-actions github-actions Bot added the enhancement New feature or request label Feb 21, 2026
@oferchen
oferchen merged commit b480c7f into master Feb 21, 2026
15 of 16 checks passed
@oferchen
oferchen deleted the feature/daemon-signal-handling branch February 21, 2026 15:17
oferchen added a commit that referenced this pull request May 1, 2026
Register Unix signal handlers at daemon startup so the server loop
responds correctly to process signals, matching upstream rsync behavior:

- SIGPIPE: Captured into a never-checked flag, replacing the default
  termination action so broken-pipe errors surface as io::Error instead
  of killing the daemon process.
- SIGHUP: Sets a reload_config AtomicBool flag checked each iteration
  of the accept loop, logging the event and notifying systemd.
- SIGTERM/SIGINT: Sets a shutdown AtomicBool flag that breaks out of
  the accept loop, allowing existing worker threads to drain naturally.

Uses signal-hook crate (safe API only, no unsafe blocks) gated behind
cfg(unix) with no-op stubs for non-Unix platforms. Both single-listener
and dual-stack accept loops now use non-blocking accept with periodic
signal flag checks instead of indefinite blocking.
oferchen added a commit that referenced this pull request May 5, 2026
Register Unix signal handlers at daemon startup so the server loop
responds correctly to process signals, matching upstream rsync behavior:

- SIGPIPE: Captured into a never-checked flag, replacing the default
  termination action so broken-pipe errors surface as io::Error instead
  of killing the daemon process.
- SIGHUP: Sets a reload_config AtomicBool flag checked each iteration
  of the accept loop, logging the event and notifying systemd.
- SIGTERM/SIGINT: Sets a shutdown AtomicBool flag that breaks out of
  the accept loop, allowing existing worker threads to drain naturally.

Uses signal-hook crate (safe API only, no unsafe blocks) gated behind
cfg(unix) with no-op stubs for non-Unix platforms. Both single-listener
and dual-stack accept loops now use non-blocking accept with periodic
signal flag checks instead of indefinite blocking.
oferchen added a commit that referenced this pull request May 18, 2026
SSE-7: cover the contract that the socketpair-backed stderr drain
landed in SSE-3 (#2372) and SSE-4 (#2373) surfaces both the child's
non-zero ExitStatus and the captured stderr bytes intact. Gated on
unix + the ssh-socketpair-stderr feature so the parity test only runs
on the path the feature wires up. Verifies both the SshConnection
wait_with_stderr and the SshChildHandle wait_with_stderr code paths.
oferchen added a commit that referenced this pull request May 18, 2026
SSE-7: cover the contract that the socketpair-backed stderr drain
landed in SSE-3 (#2372) and SSE-4 (#2373) surfaces both the child's
non-zero ExitStatus and the captured stderr bytes intact. Gated on
unix + the ssh-socketpair-stderr feature so the parity test only runs
on the path the feature wires up. Verifies both the SshConnection
wait_with_stderr and the SshChildHandle wait_with_stderr code paths.
oferchen added a commit that referenced this pull request May 18, 2026
SSE-7: cover the contract that the socketpair-backed stderr drain
landed in SSE-3 (#2372) and SSE-4 (#2373) surfaces both the child's
non-zero ExitStatus and the captured stderr bytes intact. Gated on
unix + the ssh-socketpair-stderr feature so the parity test only runs
on the path the feature wires up. Verifies both the SshConnection
wait_with_stderr and the SshChildHandle wait_with_stderr code paths.
oferchen added a commit that referenced this pull request May 18, 2026
SSE-7: cover the contract that the socketpair-backed stderr drain
landed in SSE-3 (#2372) and SSE-4 (#2373) surfaces both the child's
non-zero ExitStatus and the captured stderr bytes intact. Gated on
unix + the ssh-socketpair-stderr feature so the parity test only runs
on the path the feature wires up. Verifies both the SshConnection
wait_with_stderr and the SshChildHandle wait_with_stderr code paths.
oferchen added a commit that referenced this pull request May 18, 2026
SSE-7: cover the contract that the socketpair-backed stderr drain
landed in SSE-3 (#2372) and SSE-4 (#2373) surfaces both the child's
non-zero ExitStatus and the captured stderr bytes intact. Gated on
unix + the ssh-socketpair-stderr feature so the parity test only runs
on the path the feature wires up. Verifies both the SshConnection
wait_with_stderr and the SshChildHandle wait_with_stderr code paths.
oferchen added a commit that referenced this pull request Aug 24, 2026
SSE-7: cover the contract that the socketpair-backed stderr drain
landed in SSE-3 (#2372) and SSE-4 (#2373) surfaces both the child's
non-zero ExitStatus and the captured stderr bytes intact. Gated on
unix + the ssh-socketpair-stderr feature so the parity test only runs
on the path the feature wires up. Verifies both the SshConnection
wait_with_stderr and the SshChildHandle wait_with_stderr code paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant