Skip to content

Handle broken pipes more gracefully - #445

Merged
01mf02 merged 3 commits into
mainfrom
broken-pipe
Aug 2, 2026
Merged

Handle broken pipes more gracefully#445
01mf02 merged 3 commits into
mainfrom
broken-pipe

Conversation

@01mf02

@01mf02 01mf02 commented Jun 29, 2026

Copy link
Copy Markdown
Owner

This handles broken pipes as reported in #444:

$ cargo run -q -- --help | :
$ echo "${PIPESTATUS}"
141
$ cargo run -q -- -n 1 | :
$ echo "${PIPESTATUS}"
141

It would be nice to unify at least two of the three broken pipe checks in the code, though ...
But this is hard, given that error printing code can fail with SIGPIPE as well ...

@oech3

oech3 commented Jun 29, 2026

Copy link
Copy Markdown

unsafe { libc::signal(libc::SIGPIPE, libc::SIG_DFL) };? Taken from uutils.

@01mf02

01mf02 commented Jul 17, 2026

Copy link
Copy Markdown
Owner Author

unsafe { libc::signal(libc::SIGPIPE, libc::SIG_DFL) };? Taken from uutils.

I rather wish to avoid unsafe code, as well as adding another (direct) dependency to jaq.

@oech3

oech3 commented Jul 17, 2026 via email

Copy link
Copy Markdown

@01mf02

01mf02 commented Jul 18, 2026

Copy link
Copy Markdown
Owner Author

I don't think thread-safe wrapper for signal is possible. (It should be used by uutils already if such wrapper is possible...)

Perhaps, but jaq does not use multiple threads, so do you think that this is relevant in this case?

@oech3

oech3 commented Jul 18, 2026 via email

Copy link
Copy Markdown

@01mf02

01mf02 commented Jul 18, 2026

Copy link
Copy Markdown
Owner Author

External crates or C libs might use threads. I'm not sure, but is signal on top of main() safe?

To be honest, I do not know. Problematic places could be filters like debug, stderr, which are printed via env_logger, and I do not know how that works under the hood. If you find some way to trigger unexpected behaviour there, I would be interested to hear about it.

@01mf02
01mf02 merged commit d5ffa6d into main Aug 2, 2026
4 checks passed
@01mf02
01mf02 deleted the broken-pipe branch August 2, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants