Skip to content

Commit 3810d4a

Browse files
committed
unix_sigpipe: Make sigpipe param docs long-form
1 parent 3d1a4e4 commit 3810d4a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Diff for: library/std/src/rt.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,25 @@ macro_rules! rtunwrap {
7272
// Runs before `main`.
7373
// SAFETY: must be called only once during runtime initialization.
7474
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
75-
// The extra parameter `sigpipe` allows rustc to generate code that instructs std whether
76-
// or not to ignore `SIGPIPE`.
75+
//
76+
// # The `sigpipe` parameter
77+
//
78+
// Since 2014, the Rust runtime on Unix has set the `SIGPIPE` handler to
79+
// `SIG_IGN`. Applications have good reasons to want a different behavior
80+
// though, so there is a `#[unix_sigpipe = "..."]` attribute on `fn main()` that
81+
// can be used to select how `SIGPIPE` shall be setup (if changed at all) before
82+
// `fn main()` is called. See <https://github.com/rust-lang/rust/issues/97889>
83+
// for more info.
84+
//
85+
// The `sigpipe` parameter to this function gets its value via the code that
86+
// rustc generates to invoke `fn lang_start()`. The reason we have `sigpipe` for
87+
// all platforms and not only Unix, is because std is not allowed to have `cfg`
88+
// directives as this high level. See the module docs in
89+
// `src/tools/tidy/src/pal.rs` for more info. On all other platforms, `sigpipe`
90+
// has a value, but its value is ignored.
91+
//
92+
// Even though it is an `u8`, it only ever has 3 values. These are documented in
93+
// `compiler/rustc_session/src/config/sigpipe.rs`.
7794
#[cfg_attr(test, allow(dead_code))]
7895
unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
7996
unsafe {

Diff for: library/std/src/sys/unix/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ pub fn init(argc: isize, argv: *const *const u8, _sigpipe: u8) {}
4949
#[cfg(not(target_os = "espidf"))]
5050
// SAFETY: must be called only once during runtime initialization.
5151
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
52-
// The extra parameter `sigpipe` allows rustc to generate code that instructs std whether
53-
// or not to ignore `SIGPIPE`.
52+
// See `fn init()` in `library/std/src/rt.rs` for docs on `sigpipe`.
5453
pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
5554
// The standard streams might be closed on application startup. To prevent
5655
// std::io::{stdin, stdout,stderr} objects from using other unrelated file

0 commit comments

Comments
 (0)