Skip to content

Commit

Permalink
Merge pull request #429 from sigmaSd/p
Browse files Browse the repository at this point in the history
Exit gracefully when there is a broken pipe error
  • Loading branch information
cyqsimon authored Oct 8, 2024
2 parents ee7643c + 70822fc commit cc11fcb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Fixed

* CI: Use Powershell Compress-Archive to create Windows binary zip #424 - @cyqsimon
* Exit gracefully when there is a broken pipe error #429 - @sigmaSd

## [0.23.0] - 2024-08-17

Expand Down
10 changes: 8 additions & 2 deletions src/os/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ fn get_interface(interface_name: &str) -> Option<NetworkInterface> {
fn create_write_to_stdout() -> Box<dyn FnMut(String) + Send> {
let mut stdout = io::stdout();
Box::new({
move |output: String| {
writeln!(stdout, "{}", output).unwrap();
move |output: String| match writeln!(stdout, "{}", output) {
Ok(_) => (),
Err(e) if e.kind() == ErrorKind::BrokenPipe => {
// A process that was listening to bandwhich stdout has exited
// We can't do much here, lets just exit as well
std::process::exit(0)
}
Err(e) => panic!("Failed to write to stdout: {e}"),
}
})
}
Expand Down

0 comments on commit cc11fcb

Please sign in to comment.