nohup: move platform code into platform/{unix,windows}.rs - #14525
nohup: move platform code into platform/{unix,windows}.rs#14525sylvestre wants to merge 1 commit into
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.
| command.stdout(find_stdout()?); | ||
| } | ||
| if std::io::stderr().is_terminal() { | ||
| command.stderr(Stdio::inherit()); |
There was a problem hiding this comment.
I was misunderstanding what replace_fds do at my PR. Can we reuse a let nohup_out = find_stdout()?
| pub(crate) fn prepare() -> UResult<()> { | ||
| replace_fds()?; | ||
|
|
||
| unsafe { libc::signal(libc::SIGHUP, libc::SIG_IGN) }; |
| if std::io::stdout().is_terminal() { | ||
| command.stdout(find_stdout()?); | ||
| } | ||
| if std::io::stderr().is_terminal() { | ||
| command.stderr(Stdio::inherit()); | ||
| } |
|
GNU testsuite comparison: |
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.