Skip to content

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

Merged
sylvestre merged 2 commits into
uutils:mainfrom
sylvestre:nohup-platform-split
Sep 13, 2026
Merged

nohup: move platform code into platform/{unix,windows}.rs#14525
sylvestre merged 2 commits 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.

Comment thread src/uu/nohup/src/platform/windows.rs Outdated
pub(crate) fn prepare() -> UResult<()> {
replace_fds()?;

unsafe { libc::signal(libc::SIGHUP, libc::SIG_IGN) };
Comment thread src/uu/nohup/src/platform/windows.rs Outdated
@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout-group (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/rm/isatty (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)

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.
Copilot AI review requested due to automatic review settings September 13, 2026 13:35

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.

🟡 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()?;
@sylvestre
sylvestre merged commit 9fa399e into uutils:main Sep 13, 2026
176 checks passed
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