Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/uu/tee/src/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@
#[cfg(not(any(unix, target_os = "wasi")))]
use io::Read as _;
const BUF_SIZE: usize = 32 * 1024;
#[cfg(all(unix, not(target_os = "fuchsia")))]
if uucore::signals::stdin_was_closed() {

This comment was marked as resolved.

let e = Error::from(rustix::io::Errno::BADF);

Check warning on line 152 in src/uu/tee/src/tee.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'BADF' (file:'src/uu/tee/src/tee.rs', line:152)
show_error!(
"{}",
translate!("tee-error-stdin", "error" => strip_errno(&e))
);
return Err(());
}
#[cfg(any(unix, target_os = "wasi"))]
let input = rustix::stdio::stdin();
#[cfg(not(any(unix, target_os = "wasi")))]
Expand Down
15 changes: 15 additions & 0 deletions tests/by-util/test_tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ fn test_error_stdin_directory() {
.stderr_is("tee: read error: Is a directory\n");
}

#[test]
#[cfg(all(unix, not(wasi_runner)))]
fn test_closed_stdin() {
// Reading a closed stdin fails with EBADF. Run through a shell so the
// process really starts with fd 0 closed.
let (at, ts) = ::uutests::at_and_ts!();
ts.cmd("sh")
.args(&["-c", "exec <&-; \"$0\" tee file"])
.arg(&ts.bin_path)
.fails_with_code(1)
.no_stdout()
.stderr_is("tee: read error: Bad file descriptor\n");
assert_eq!(at.read("file"), "");
}

#[test]
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
Expand Down
Loading