Skip to content

nohup: move platform code into platform/{unix,windows}.rs - #14525

Open
sylvestre wants to merge 1 commit into
uutils:mainfrom
sylvestre:nohup-platform-split
Open

nohup: move platform code into platform/{unix,windows}.rs#14525
sylvestre wants to merge 1 commit into
uutils:mainfrom
sylvestre:nohup-platform-split

Conversation

@sylvestre

Copy link
Copy Markdown
Contributor

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.

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.
Copilot AI lite review requested due to automatic review settings September 12, 2026 21:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PlatformError so NohupError stays platform-agnostic.
  • Updates nohup.rs to delegate platform behavior to platform::*.

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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) };
Comment on lines +33 to +38
if std::io::stdout().is_terminal() {
command.stdout(find_stdout()?);
}
if std::io::stderr().is_terminal() {
command.stderr(Stdio::inherit());
}
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/io-errors (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/seq/seq-epipe is now passing!
Congrats! The gnu test tests/tail/pipe-f is now passing!
Note: The gnu test tests/env/env-signal-handler was skipped on 'main' but is now failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants