From 5cef328aa3c3f2fedda3d4830e464f6f25221272 Mon Sep 17 00:00:00 2001 From: Christopher Dryden Date: Wed, 17 Dec 2025 14:59:40 +0000 Subject: [PATCH 1/2] nohup: use POSIXLY_CORRECT to determine failure exit code --- src/uu/nohup/src/nohup.rs | 19 +++++++++++++------ tests/by-util/test_nohup.rs | 13 +++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index 28292ac4154..a51359ea277 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -55,10 +55,20 @@ impl UError for NohupError { } } +fn failure_code() -> i32 { + match env::var("POSIXLY_CORRECT") { + Ok(_) => POSIX_NOHUP_FAILURE, + Err(_) => EXIT_CANCELED, + } +} + #[uucore::main] pub fn uumain(args: impl uucore::Args) -> UResult<()> { - let matches = - uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 125)?; + let matches = uucore::clap_localization::handle_clap_result_with_exit_code( + uu_app(), + args, + failure_code(), + )?; replace_fds()?; @@ -124,10 +134,7 @@ fn replace_fds() -> UResult<()> { } fn find_stdout() -> UResult { - let internal_failure_code = match env::var("POSIXLY_CORRECT") { - Ok(_) => POSIX_NOHUP_FAILURE, - Err(_) => EXIT_CANCELED, - }; + let internal_failure_code = failure_code(); match OpenOptions::new() .create(true) diff --git a/tests/by-util/test_nohup.rs b/tests/by-util/test_nohup.rs index 2349b2dc2a8..f3fa0bc948c 100644 --- a/tests/by-util/test_nohup.rs +++ b/tests/by-util/test_nohup.rs @@ -14,8 +14,17 @@ use uutests::util_name; // All that can be tested is the side-effects. #[test] -fn test_invalid_arg() { - new_ucmd!().arg("--definitely-invalid").fails_with_code(125); +fn test_nohup_exit_codes() { + // No args: 125 default, 127 with POSIXLY_CORRECT + new_ucmd!().fails_with_code(125); + new_ucmd!().env("POSIXLY_CORRECT", "1").fails_with_code(127); + + // Invalid arg: 125 default, 127 with POSIXLY_CORRECT + new_ucmd!().arg("--invalid").fails_with_code(125); + new_ucmd!() + .env("POSIXLY_CORRECT", "1") + .arg("--invalid") + .fails_with_code(127); } #[test] From 9c5518991982ae2ffd53b15ea3a140102fdde746 Mon Sep 17 00:00:00 2001 From: Chris Dryden Date: Thu, 18 Dec 2025 10:40:01 -0500 Subject: [PATCH 2/2] Update env value checking Co-authored-by: Daniel Hofstetter --- src/uu/nohup/src/nohup.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/uu/nohup/src/nohup.rs b/src/uu/nohup/src/nohup.rs index a51359ea277..38b5e5ceb30 100644 --- a/src/uu/nohup/src/nohup.rs +++ b/src/uu/nohup/src/nohup.rs @@ -56,9 +56,10 @@ impl UError for NohupError { } fn failure_code() -> i32 { - match env::var("POSIXLY_CORRECT") { - Ok(_) => POSIX_NOHUP_FAILURE, - Err(_) => EXIT_CANCELED, + if env::var("POSIXLY_CORRECT").is_ok() { + POSIX_NOHUP_FAILURE + } else { + EXIT_CANCELED } }