From 2986bfed613a4967e4af20721f89c4afb9a635a6 Mon Sep 17 00:00:00 2001 From: Rain Date: Sat, 27 Jul 2024 02:06:58 +0000 Subject: [PATCH] [illumos/solaris] set MSG_NOSIGNAL while writing to sockets Both these platforms have MSG_NOSIGNAL available, and we should set it for socket writes in the event that the SIGPIPE handler has been reset to SIG_DFL (i.e. terminate the process). I've verified via a quick program at https://github.com/sunshowers/msg-nosignal-test/ that even when the SIGPIPE handler is reset to SIG_DFL, writes to closed sockets now error out with EPIPE. (Under ordinary circumstances UDP writes won't cause MSG_NOSIGNAL.) --- std/src/os/unix/net/datagram.rs | 4 ++++ std/src/sys_common/net.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/std/src/os/unix/net/datagram.rs b/std/src/os/unix/net/datagram.rs index b29f9099a1111..f58f9b4d9ab85 100644 --- a/std/src/os/unix/net/datagram.rs +++ b/std/src/os/unix/net/datagram.rs @@ -20,6 +20,8 @@ use crate::{fmt, io}; target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", + target_os = "solaris", + target_os = "illumos", target_os = "haiku", target_os = "nto", ))] @@ -31,6 +33,8 @@ use libc::MSG_NOSIGNAL; target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", + target_os = "solaris", + target_os = "illumos", target_os = "haiku", target_os = "nto", )))] diff --git a/std/src/sys_common/net.rs b/std/src/sys_common/net.rs index 95ca67fc2e0b6..0a82b50ae1ab6 100644 --- a/std/src/sys_common/net.rs +++ b/std/src/sys_common/net.rs @@ -42,6 +42,7 @@ cfg_if::cfg_if! { target_os = "hurd", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", + target_os = "solaris", target_os = "illumos", target_os = "haiku", target_os = "nto"))] { use libc::MSG_NOSIGNAL; } else {