Signals: Compute signal set once on startup
Some checks failed
make test / ubuntu (push) Has been cancelled
make test / ubuntu-32bit-static-pcre2 (push) Has been cancelled
make test / ubuntu-asan (push) Has been cancelled
make test / macos (push) Has been cancelled
Rust checks / rustfmt (push) Has been cancelled
Rust checks / clippy (push) Has been cancelled

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 #10869
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

View File

@ -3,7 +3,7 @@
use super::blocked_signals_for_job; use super::blocked_signals_for_job;
use crate::proc::Job; use crate::proc::Job;
use crate::redirection::Dup2List; 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 crate::{exec::is_thompson_shell_script, libc::_PATH_BSHELL};
use errno::Errno; use errno::Errno;
use libc::{c_char, posix_spawn_file_actions_t, posix_spawnattr_t}; use libc::{c_char, posix_spawn_file_actions_t, posix_spawnattr_t};
@ -126,8 +126,7 @@ impl PosixSpawner {
} }
// Everybody gets default handlers. // Everybody gets default handlers.
let sigdefault = get_signals_to_default(); attr.set_sigdefault(&signals_to_default)?;
attr.set_sigdefault(&sigdefault)?;
// Reset the sigmask. // Reset the sigmask.
let mut sigmask = unsafe { std::mem::zeroed() }; 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::wchar::prelude::*;
use crate::wutil::{fish_wcstoi, perror}; use crate::wutil::{fish_wcstoi, perror};
use errno::{errno, set_errno}; use errno::{errno, set_errno};
use once_cell::sync::Lazy;
use std::sync::atomic::{AtomicI32, Ordering}; use std::sync::atomic::{AtomicI32, Ordering};
/// Store the "main" pid. This allows us to reliably determine if we are in a forked child. /// 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()); 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() }; let mut set: libc::sigset_t = unsafe { std::mem::zeroed() };
unsafe { libc::sigemptyset(&mut set) }; unsafe { libc::sigemptyset(&mut set) };
for data in SIGNAL_TABLE.iter() { 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()) }; unsafe { libc::sigaddset(&mut set, data.signal.code()) };
} }
return set; return set;
} });
/// Ensure we did not inherit any blocked signals. See issue #3964. /// Ensure we did not inherit any blocked signals. See issue #3964.
pub fn signal_unblock_all() { pub fn signal_unblock_all() {