Change SIGPIPE ui from #[unix_sigpipe = "..."] to -Zon-broken-pipe=...
In the stabilization attempt of `#[unix_sigpipe = "sig_dfl"]`, a concern was raised related to using a language attribute for the feature: Long term, we want `fn lang_start()` to be definable by any crate, not just libstd. Having a special language attribute in that case becomes awkward. So as a first step towards towards the next stabilization attempt, this PR changes the `#[unix_sigpipe = "..."]` attribute to a compiler flag `-Zon-broken-pipe=...` to remove that concern, since now the language is not "contaminated" by this feature. Another point was also raised, namely that the ui should not leak **how** it does things, but rather what the **end effect** is. The new flag uses the proposed naming. This is of course something that can be iterated on further before stabilization.
This commit is contained in:
@@ -55,8 +55,8 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
|
||||
// want!
|
||||
//
|
||||
// Hence, we set SIGPIPE to ignore when the program starts up in order
|
||||
// to prevent this problem. Add `#[unix_sigpipe = "..."]` above `fn main()` to
|
||||
// alter this behavior.
|
||||
// to prevent this problem. Use `-Zon-broken-pipe=...` to alter this
|
||||
// behavior.
|
||||
reset_sigpipe(sigpipe);
|
||||
|
||||
stack_overflow::init();
|
||||
@@ -194,7 +194,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
|
||||
_ => unreachable!(),
|
||||
};
|
||||
if sigpipe_attr_specified {
|
||||
UNIX_SIGPIPE_ATTR_SPECIFIED.store(true, crate::sync::atomic::Ordering::Relaxed);
|
||||
ON_BROKEN_PIPE_FLAG_USED.store(true, crate::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
if let Some(handler) = handler {
|
||||
rtassert!(signal(libc::SIGPIPE, handler) != libc::SIG_ERR);
|
||||
@@ -214,7 +214,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {
|
||||
target_os = "fuchsia",
|
||||
target_os = "horizon",
|
||||
)))]
|
||||
static UNIX_SIGPIPE_ATTR_SPECIFIED: crate::sync::atomic::AtomicBool =
|
||||
static ON_BROKEN_PIPE_FLAG_USED: crate::sync::atomic::AtomicBool =
|
||||
crate::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
#[cfg(not(any(
|
||||
@@ -223,8 +223,8 @@ static UNIX_SIGPIPE_ATTR_SPECIFIED: crate::sync::atomic::AtomicBool =
|
||||
target_os = "fuchsia",
|
||||
target_os = "horizon",
|
||||
)))]
|
||||
pub(crate) fn unix_sigpipe_attr_specified() -> bool {
|
||||
UNIX_SIGPIPE_ATTR_SPECIFIED.load(crate::sync::atomic::Ordering::Relaxed)
|
||||
pub(crate) fn on_broken_pipe_flag_used() -> bool {
|
||||
ON_BROKEN_PIPE_FLAG_USED.load(crate::sync::atomic::Ordering::Relaxed)
|
||||
}
|
||||
|
||||
// SAFETY: must be called only once during runtime cleanup.
|
||||
|
||||
@@ -353,11 +353,11 @@ impl Command {
|
||||
// Inherit the signal mask from the parent rather than resetting it (i.e. do not call
|
||||
// pthread_sigmask).
|
||||
|
||||
// If #[unix_sigpipe] is specified, don't reset SIGPIPE to SIG_DFL.
|
||||
// If #[unix_sigpipe] is not specified, reset SIGPIPE to SIG_DFL for backward compatibility.
|
||||
// If -Zon-broken-pipe is used, don't reset SIGPIPE to SIG_DFL.
|
||||
// If -Zon-broken-pipe is not used, reset SIGPIPE to SIG_DFL for backward compatibility.
|
||||
//
|
||||
// #[unix_sigpipe] is an opportunity to change the default here.
|
||||
if !crate::sys::pal::unix_sigpipe_attr_specified() {
|
||||
// -Zon-broken-pipe is an opportunity to change the default here.
|
||||
if !crate::sys::pal::on_broken_pipe_flag_used() {
|
||||
#[cfg(target_os = "android")] // see issue #88585
|
||||
{
|
||||
let mut action: libc::sigaction = mem::zeroed();
|
||||
@@ -455,7 +455,7 @@ impl Command {
|
||||
) -> io::Result<Option<Process>> {
|
||||
use crate::mem::MaybeUninit;
|
||||
use crate::sys::weak::weak;
|
||||
use crate::sys::{self, cvt_nz, unix_sigpipe_attr_specified};
|
||||
use crate::sys::{self, cvt_nz, on_broken_pipe_flag_used};
|
||||
|
||||
if self.get_gid().is_some()
|
||||
|| self.get_uid().is_some()
|
||||
@@ -617,11 +617,11 @@ impl Command {
|
||||
// Inherit the signal mask from this process rather than resetting it (i.e. do not call
|
||||
// posix_spawnattr_setsigmask).
|
||||
|
||||
// If #[unix_sigpipe] is specified, don't reset SIGPIPE to SIG_DFL.
|
||||
// If #[unix_sigpipe] is not specified, reset SIGPIPE to SIG_DFL for backward compatibility.
|
||||
// If -Zon-broken-pipe is used, don't reset SIGPIPE to SIG_DFL.
|
||||
// If -Zon-broken-pipe is not used, reset SIGPIPE to SIG_DFL for backward compatibility.
|
||||
//
|
||||
// #[unix_sigpipe] is an opportunity to change the default here.
|
||||
if !unix_sigpipe_attr_specified() {
|
||||
// -Zon-broken-pipe is an opportunity to change the default here.
|
||||
if !on_broken_pipe_flag_used() {
|
||||
let mut default_set = MaybeUninit::<libc::sigset_t>::uninit();
|
||||
cvt(sigemptyset(default_set.as_mut_ptr()))?;
|
||||
cvt(sigaddset(default_set.as_mut_ptr(), libc::SIGPIPE))?;
|
||||
|
||||
Reference in New Issue
Block a user