1

Support `#[unix_sigpipe = "inherit|sig_dfl"]` on `fn main()` to preven...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/97802
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Contributor

@Enselic Enselic commented on Jun 6

edited

When enabled, programs don't have to explicitly handle ErrorKind::BrokenPipe any longer. Currently, the program

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

#![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 #62569 and referenced issues for discussions regarding the SIGPIPE problem itself

See the this Zulip topic for more discussions, including about this PR.

Tracking issue: #97889

HarrisonMc555, wchargin, yerke, joshtriplett, and Xiretza reacted with thumbs up emoji All reactions

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK