Signals: Compute signal set once on startup

Really the only thing we're looking for here is if we're started with
HUP ignored or not.

Saves a syscall per external process.

Continuation of 
This commit is contained in:
Fabian Boehm 2024-12-04 20:14:25 +01:00
parent 3012020af3
commit e24823dd6c
2 changed files with 5 additions and 5 deletions
src

View File

@ -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() };

View File

@ -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<libc::sigset_t> = 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() {