feat: implement Windows console signal handling for daemon mode#3041
Merged
feat: implement Windows console signal handling for daemon mode#3041
Conversation
Replace the no-op Windows signal handler stub with a real SetConsoleCtrlHandler implementation: - CTRL_C_EVENT and CTRL_CLOSE_EVENT set the shutdown flag - CTRL_BREAK_EVENT sets the graceful_exit flag Also gates daemonize.rs functions with #[cfg(unix)] since fork/setsid are Unix-only. Adds the windows crate dependency with Win32_System_Console and Win32_Foundation features. Includes the full Windows daemon design document covering all 3 phases: console signals (this PR), privilege/name resolution, and SCM service.
Remove redundant comments that restate the code. Keep upstream references (main.c SIGACT) and non-obvious context (SIGPIPE prevents daemon termination). Tighten struct field docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SetConsoleCtrlHandlerimplementationshutdownflag (same as SIGTERM/SIGINT on Unix)graceful_exitflag (same as SIGUSR1 on Unix)daemonize.rsfunctions with#[cfg(unix)]sincefork/setsidare Unix-onlywindowscrate dependency withWin32_System_ConsoleandWin32_Foundationfeaturesdocs/plans/2026-03-29-windows-daemon-design.md)This is Phase 1 of 3 for full Windows daemon support. Phase 2 adds privilege dropping and name resolution. Phase 3 adds Windows Service (SCM) integration.
Test plan
SetConsoleCtrlHandlerwindows_register_signal_handlers_succeedstest passes on Windows#[cfg(all(test, unix))]