From f6beddb7494e71f91e0a7af98f8b45c0721e2b52 Mon Sep 17 00:00:00 2001 From: Noemi <45180344+unflxw@users.noreply.github.com> Date: Thu, 7 Nov 2024 15:14:57 +0100 Subject: [PATCH] Restore default (ignore) Rust SIGPIPE behavior Remove `reset_sigpipe` and other code that handles `SIGPIPE` in any way, such as ignoring it or forwarding it to the child process. This restores the default behaviour of the Rust standard library, which is to always ignore the signal. This behaviour will be inherited by the child process. See #12 for context. --- src/main.rs | 4 +--- src/signals.rs | 21 +-------------------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2826ab4..534084c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use crate::cli::Cli; use crate::client::client; use crate::log::{LogConfig, LogMessage, LogSeverity}; use crate::package::NAME; -use crate::signals::{has_terminating_intent, reset_sigpipe, signal_stream}; +use crate::signals::{has_terminating_intent, signal_stream}; use crate::timestamp::SystemTimestamp; use ::log::{debug, error, trace}; @@ -38,8 +38,6 @@ use clap::Parser; use env_logger::Env; fn main() { - reset_sigpipe(); - env_logger::Builder::from_env(Env::default().default_filter_or("info")) .format(|buf, record| { let level = record.level().to_string().to_ascii_lowercase(); diff --git a/src/signals.rs b/src/signals.rs index bcb1bc2..c11048d 100644 --- a/src/signals.rs +++ b/src/signals.rs @@ -9,7 +9,6 @@ fn nix_to_tokio(signal: &Signal) -> SignalKind { Signal::SIGTERM => SignalKind::terminate(), Signal::SIGHUP => SignalKind::hangup(), Signal::SIGQUIT => SignalKind::quit(), - Signal::SIGPIPE => SignalKind::pipe(), Signal::SIGUSR1 => SignalKind::user_defined1(), Signal::SIGUSR2 => SignalKind::user_defined2(), Signal::SIGWINCH => SignalKind::window_change(), @@ -25,7 +24,7 @@ fn nix_to_tokio(signal: &Signal) -> SignalKind { // This list only includes signals that can be caught and handled by the // application. Signals that cannot be caught, such as SIGKILL and SIGSTOP, // are not included. -const CHILD_FORWARDABLE_SIGNALS: [Signal; 8] = [ +const CHILD_FORWARDABLE_SIGNALS: [Signal; 7] = [ Signal::SIGUSR1, Signal::SIGUSR2, Signal::SIGWINCH, @@ -33,7 +32,6 @@ const CHILD_FORWARDABLE_SIGNALS: [Signal; 8] = [ Signal::SIGTERM, Signal::SIGHUP, Signal::SIGQUIT, - Signal::SIGPIPE, ]; // Returns whether a signal returned by a `signal_stream` represents an intent @@ -50,7 +48,6 @@ const CHILD_FORWARDABLE_SIGNALS: [Signal; 8] = [ // - `SIGWINCH`, which notifies the process of a terminal resize (and whose default // behaviour is to be ignored) // - `SIGHUP`, which is sometimes used to trigger configuration refreshes -// - `SIGPIPE`, which notifies the process of a broken pipe // // The objective is to ensure that only signals which were sent with the explicit // intent to terminate the child process cause this process to terminate. @@ -70,19 +67,3 @@ pub fn signal_stream() -> io::Result> { Ok(signals.map(|(signal, _)| signal)) } - -// This function resets the SIGPIPE signal to its default behavior. -// It is called at the beginning of the program. -// -// Signal handlers are inherited by child processes, and most software -// expects SIGPIPE to be set to its default behavior. However, -// the Rust standard library sets SIGPIPE to be ignored by default, which -// can cause the child processes to behave differently than expected. -// -// See https://github.com/kurtbuilds/sigpipe (and the discussions linked -// in the README) for more information. -pub fn reset_sigpipe() { - unsafe { - libc::signal(libc::SIGPIPE, libc::SIG_DFL); - } -}