diff --git a/Cargo.lock b/Cargo.lock index 62c0679f4b0..ed6b32d2a4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4375,6 +4375,7 @@ dependencies = [ "clap", "fluent", "itertools 0.14.0", + "libc", "uucore", ] diff --git a/src/uu/yes/Cargo.toml b/src/uu/yes/Cargo.toml index b8703bb55d1..267c9fedf6a 100644 --- a/src/uu/yes/Cargo.toml +++ b/src/uu/yes/Cargo.toml @@ -24,6 +24,7 @@ itertools = { workspace = true } fluent = { workspace = true } [target.'cfg(unix)'.dependencies] +libc = { workspace = true } uucore = { workspace = true, features = ["pipes", "signals"] } [target.'cfg(not(unix))'.dependencies] diff --git a/src/uu/yes/src/yes.rs b/src/uu/yes/src/yes.rs index 22c84a1a212..086471271ce 100644 --- a/src/uu/yes/src/yes.rs +++ b/src/uu/yes/src/yes.rs @@ -112,6 +112,11 @@ fn prepare_buffer(buf: &mut Vec) { } pub fn exec(bytes: &[u8]) -> io::Result<()> { + #[cfg(unix)] + if uucore::signals::stdout_was_closed() { + return Err(io::Error::from_raw_os_error(libc::EBADF)); + } + let stdout = io::stdout(); let mut stdout = stdout.lock();