diff --git a/src/fork_exec/spawn.rs b/src/fork_exec/spawn.rs index 6c3e421d0..6a2e772e0 100644 --- a/src/fork_exec/spawn.rs +++ b/src/fork_exec/spawn.rs @@ -3,7 +3,7 @@ use super::blocked_signals_for_job; use crate::proc::Job; use crate::redirection::Dup2List; -use crate::signal::get_signals_to_default; +use crate::signal::signals_to_default; use crate::{exec::is_thompson_shell_script, libc::_PATH_BSHELL}; use errno::Errno; use libc::{c_char, posix_spawn_file_actions_t, posix_spawnattr_t}; @@ -126,8 +126,7 @@ impl PosixSpawner { } // Everybody gets default handlers. - let sigdefault = get_signals_to_default(); - attr.set_sigdefault(&sigdefault)?; + attr.set_sigdefault(&signals_to_default)?; // Reset the sigmask. let mut sigmask = unsafe { std::mem::zeroed() }; diff --git a/src/signal.rs b/src/signal.rs index 322cadb45..6aa995f98 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -10,6 +10,7 @@ use crate::topic_monitor::{topic_monitor_principal, Generation, GenerationsList, use crate::wchar::prelude::*; use crate::wutil::{fish_wcstoi, perror}; use errno::{errno, set_errno}; +use once_cell::sync::Lazy; use std::sync::atomic::{AtomicI32, Ordering}; /// Store the "main" pid. This allows us to reliably determine if we are in a forked child. @@ -275,7 +276,7 @@ pub fn signal_handle(sig: Signal) { sigaction(sig, &act, std::ptr::null_mut()); } -pub fn get_signals_to_default() -> libc::sigset_t { +pub static signals_to_default: Lazy = Lazy::new(|| { let mut set: libc::sigset_t = unsafe { std::mem::zeroed() }; unsafe { libc::sigemptyset(&mut set) }; for data in SIGNAL_TABLE.iter() { @@ -292,7 +293,7 @@ pub fn get_signals_to_default() -> libc::sigset_t { unsafe { libc::sigaddset(&mut set, data.signal.code()) }; } return set; -} +}); /// Ensure we did not inherit any blocked signals. See issue #3964. pub fn signal_unblock_all() {