mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-09 03:51:20 -03:00
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 #10869
This commit is contained in:
@@ -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 @@ pub fn new(j: &Job, dup2s: &Dup2List) -> Result<PosixSpawner, Errno> {
|
||||
}
|
||||
|
||||
// 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() };
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user