nohup: move platform code into platform/{unix,windows}.rs - #14525
Conversation
Instead of scattering #[cfg(unix)] / #[cfg(windows)] through nohup.rs, keep the platform-specific code in its own file behind a small shared interface: prepare(), run() and set_output_file_mode(). The unix-only CannotDetach/CannotReplace variants move to a unix PlatformError, so NohupError in nohup.rs is now platform independent.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Refactors nohup to centralize platform-specific behavior behind a shared interface (prepare(), run(), set_output_file_mode()), reducing scattered #[cfg(...)] blocks and making nohup.rs platform-independent.
Changes:
- Adds new Unix and Windows platform modules implementing a common interface.
- Moves Unix-only detach/FD-replace failures into a Unix
PlatformErrorsoNohupErrorstays platform-agnostic. - Updates
nohup.rsto delegate platform behavior toplatform::*.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/uu/nohup/src/platform/windows.rs | Introduces Windows-specific prepare/run/set_output_file_mode implementation. |
| src/uu/nohup/src/platform/unix.rs | Introduces Unix-specific detach, fd replacement, and output-file-mode logic with Unix-only errors. |
| src/uu/nohup/src/nohup.rs | Switches to platform modules and removes embedded platform-specific logic/errors. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| pub(crate) fn prepare() -> UResult<()> { | ||
| replace_fds()?; | ||
|
|
||
| unsafe { libc::signal(libc::SIGHUP, libc::SIG_IGN) }; |
|
GNU testsuite comparison: |
A DETACHED_PROCESS child has no console, so leaving stderr on inherit() dropped its output. Point it at the child's stdout the way replace_fds() does with dup2_stderr(stdout()) on Unix: at nohup.out when stdout is a terminal, at the existing redirection otherwise. find_stdout() appends to nohup.out and reports it on stderr, so it is called once and the handle is cloned for stderr rather than reopened.
There was a problem hiding this comment.
🟡 Changes recommended
Add Windows regression coverage for the affected redirection paths.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
| // `find_stdout` appends to `nohup.out` and reports it on stderr, so it | ||
| // must only be called once: give the child a second handle to the very | ||
| // same file instead of opening it again. | ||
| let nohup_out = find_stdout()?; |
Instead of scattering #[cfg(unix)] / #[cfg(windows)] through nohup.rs, keep the platform-specific code in its own file behind a small shared interface: prepare(), run() and set_output_file_mode().
The unix-only CannotDetach/CannotReplace variants move to a unix PlatformError, so NohupError in nohup.rs is now platform independent.