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
9 changes: 7 additions & 2 deletions src/uu/seq/src/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// file that was distributed with this source code.
// spell-checker:ignore (ToDO) bigdecimal extendedbigdecimal numberparse hexadecimalfloat biguint
use std::ffi::{OsStr, OsString};
use std::io::{BufWriter, ErrorKind, Write, stdout};
use std::io::{BufWriter, Write, stdout};

use clap::{Arg, ArgAction, Command};
use num_bigint::BigUint;
Expand Down Expand Up @@ -211,7 +211,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

match result {
Ok(()) => Ok(()),
Err(err) if err.kind() == ErrorKind::BrokenPipe => Ok(()),
Err(err) if err.kind() == std::io::ErrorKind::BrokenPipe => {
// GNU seq prints the Broken pipe message but still exits with status 0
let err = err.map_err_context(|| "write error".into());
uucore::show_error!("{err}");
Ok(())
}
Err(err) => Err(err.map_err_context(|| "write error".into())),
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/by-util/test_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
}

#[test]
#[cfg(unix)]
fn test_broken_pipe_still_exits_success() {
use std::process::Stdio;

let mut child = new_ucmd!()
.args(&["1", "5"])
.set_stdout(Stdio::piped())
.run_no_wait();

// Trigger a Broken pipe by writing to a pipe whose reader closed first.
child.close_stdout();
let result = child.wait().unwrap();

result
.code_is(0)
.stderr_contains("write error: Broken pipe");
}

#[test]
fn test_no_args() {
new_ucmd!()
Expand Down
Loading