From f1c8accf90d797ef32a56ee08ed7705a4b500c17 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Fri, 10 Sep 2021 19:36:51 +0200 Subject: [PATCH 1/3] Use `libc::sigaction()` instead of `sys::signal()` to prevent a deadlock --- library/std/src/sys/unix/process/process_unix.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index 12edf04a4e2e9..13b384d8899f8 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -333,10 +333,9 @@ impl Command { let mut set = MaybeUninit::::uninit(); cvt(sigemptyset(set.as_mut_ptr()))?; cvt(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), ptr::null_mut()))?; - let ret = sys::signal(libc::SIGPIPE, libc::SIG_DFL); - if ret == libc::SIG_ERR { - return Err(io::Error::last_os_error()); - } + let mut action: libc::sigaction = mem::zeroed(); + action.sa_sigaction = libc::SIG_DFL; + cvt(libc::sigaction(libc::SIGPIPE, &action as *const _, ptr::null_mut()))?; } for callback in self.get_closures().iter_mut() { From e3e5ae91d07f7d4256acac7abac6a204b6abc491 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 28 Sep 2021 21:17:57 -0700 Subject: [PATCH 2/3] Clean up unneeded explicit pointer cast The reference automatically coerces to a pointer. Writing an explicit cast here is slightly misleading because that's most commonly used when a pointer needs to be converted from one pointer type to another, e.g. `*const c_void` to `*const sigaction` or vice versa. --- library/std/src/sys/unix/process/process_unix.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index 13b384d8899f8..caef9914ac2a7 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -335,7 +335,7 @@ impl Command { cvt(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), ptr::null_mut()))?; let mut action: libc::sigaction = mem::zeroed(); action.sa_sigaction = libc::SIG_DFL; - cvt(libc::sigaction(libc::SIGPIPE, &action as *const _, ptr::null_mut()))?; + cvt(libc::sigaction(libc::SIGPIPE, &action, ptr::null_mut()))?; } for callback in self.get_closures().iter_mut() { From 65ef265c121c90e33dd9dd2dc3b919cf37209b71 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Fri, 1 Oct 2021 21:22:18 +0200 Subject: [PATCH 3/3] Call `libc::sigaction()` only on Android --- .../std/src/sys/unix/process/process_unix.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index caef9914ac2a7..5837c1553ec21 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -333,9 +333,20 @@ impl Command { let mut set = MaybeUninit::::uninit(); cvt(sigemptyset(set.as_mut_ptr()))?; cvt(libc::pthread_sigmask(libc::SIG_SETMASK, set.as_ptr(), ptr::null_mut()))?; - let mut action: libc::sigaction = mem::zeroed(); - action.sa_sigaction = libc::SIG_DFL; - cvt(libc::sigaction(libc::SIGPIPE, &action, ptr::null_mut()))?; + + #[cfg(target_os = "android")] // see issue #88585 + { + let mut action: libc::sigaction = mem::zeroed(); + action.sa_sigaction = libc::SIG_DFL; + cvt(libc::sigaction(libc::SIGPIPE, &action, ptr::null_mut()))?; + } + #[cfg(not(target_os = "android"))] + { + let ret = sys::signal(libc::SIGPIPE, libc::SIG_DFL); + if ret == libc::SIG_ERR { + return Err(io::Error::last_os_error()); + } + } } for callback in self.get_closures().iter_mut() {