Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/uu/nohup/src/nohup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,21 @@ impl UError for NohupError {
}
}

fn failure_code() -> i32 {
if env::var("POSIXLY_CORRECT").is_ok() {
POSIX_NOHUP_FAILURE
} else {
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()?;

Expand Down Expand Up @@ -124,10 +135,7 @@ fn replace_fds() -> UResult<()> {
}

fn find_stdout() -> UResult<File> {
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)
Expand Down
13 changes: 11 additions & 2 deletions tests/by-util/test_nohup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading