-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support #[unix_sigpipe = "inherit|sig_dfl"]
on fn main()
to prevent ignoring SIGPIPE
#97802
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
no_ignore_sigpipe
to never start ignoring SIGPIPE
#![no_ignore_sigpipe]
to stop libstd from ignoring SIGPIPE
#![no_ignore_sigpipe]
to stop libstd from ignoring SIGPIPE
#![ignore_sigpipe(no)]
to stop libstd from ignoring SIGPIPE
2cf4a23
to
cf341ec
Compare
#![ignore_sigpipe(no)]
to stop libstd from ignoring SIGPIPE
#![sigpipe_handler(unchanged)]
to prevent libstd from ignoring SIGPIPE
87ea353
to
fe3f47d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I consider this PR feature complete now. I'm sure there is more bike-shedding to do on what to call the attribute, and I'm sure you'll find things to comment on, but I'm happy with the implementation and the scope of the tests I added. I need to add a section to the unstable book, but I would prefer to do that after the bike-shedding is done. Looking forward to a new code review round. If you want to me to split out some parts into separate PRs that would be fine, just let me know. I had to do a rebase and took the opportunity to squash all my commits together, but I have already added some more commits. I plan on squashing again next time I need to rebase. I'm also adding T-lang as requested. @rustbot label -S-waiting-on-author +S-waiting-on-review +T-lang |
4c97eb7
to
2f738f9
Compare
#![sigpipe_handler(unchanged)]
to prevent libstd from ignoring SIGPIPE
#[pipeable]
on fn main()
to prevent ignoring SIGPIPE
This comment has been minimized.
This comment has been minimized.
My fault, sorry; I missed that the standard library was referring to the compiler, rather than the other way around. I think we should just duplicate this and put a comment in each pointing to the other; it doesn't seem worth attempting to deduplicate. |
An So, exposing them perma-unstable would IMO be preferable over But yeah duplicating these 4 constants might not be so bad. |
Thank you for further input, looking forward to another review round! I have addressed the comments now. @rustbot ready |
New version looks good to me. @RalfJung? |
☀️ Test successful - checks-actions |
Tested on commit rust-lang/rust@8c6ce6b. Direct link to PR: <rust-lang/rust#97802> 💔 miri on windows: test-fail → build-fail (cc @oli-obk @RalfJung). 💔 miri on linux: test-pass → build-fail (cc @oli-obk @RalfJung).
Finished benchmarking commit (8c6ce6b): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
Fixed by rust-lang/miri#2532 (I already pinged oli-obk and RalfJung, so I removed |
…, r=joshtriplett Support `#[unix_sigpipe = "inherit|sig_dfl"]` on `fn main()` to prevent ignoring `SIGPIPE` When enabled, programs don't have to explicitly handle `ErrorKind::BrokenPipe` any longer. Currently, the program ```rust fn main() { loop { println!("hello world"); } } ``` will print an error if used with a short-lived pipe, e.g. % ./main | head -n 1 hello world thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', library/std/src/io/stdio.rs:1016:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace by enabling `#[unix_sigpipe = "sig_dfl"]` like this ```rust #![feature(unix_sigpipe)] #[unix_sigpipe = "sig_dfl"] fn main() { loop { println!("hello world"); } } ``` there is no error, because `SIGPIPE` will not be ignored and thus the program will be killed appropriately: % ./main | head -n 1 hello world The current libstd behaviour of ignoring `SIGPIPE` before `fn main()` can be explicitly requested by using `#[unix_sigpipe = "sig_ign"]`. With `#[unix_sigpipe = "inherit"]`, no change at all is made to `SIGPIPE`, which typically means the behaviour will be the same as `#[unix_sigpipe = "sig_dfl"]`. See rust-lang#62569 and referenced issues for discussions regarding the `SIGPIPE` problem itself See the [this](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Proposal.3A.20First.20step.20towards.20solving.20the.20SIGPIPE.20problem) Zulip topic for more discussions, including about this PR. Tracking issue: rust-lang#97889
When enabled, programs don't have to explicitly handle
ErrorKind::BrokenPipe
any longer. Currently, the programwill print an error if used with a short-lived pipe, e.g.
by enabling
#[unix_sigpipe = "sig_dfl"]
like thisthere is no error, because
SIGPIPE
will not be ignored and thus the program will be killed appropriately:The current libstd behaviour of ignoring
SIGPIPE
beforefn main()
can be explicitly requested by using#[unix_sigpipe = "sig_ign"]
.With
#[unix_sigpipe = "inherit"]
, no change at all is made toSIGPIPE
, which typically means the behaviour will be the same as#[unix_sigpipe = "sig_dfl"]
.See #62569 and referenced issues for discussions regarding the
SIGPIPE
problem itselfSee the this Zulip topic for more discussions, including about this PR.
Tracking issue: #97889