mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 13:01:21 -03:00
Rename Signal to RawSignal to make way for nix Signal
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
use crate::parse_tree::NodeRef;
|
||||
use crate::parser_keywords::parser_keywords_is_reserved;
|
||||
use crate::proc::{InternalJobId, Pid};
|
||||
use crate::signal::Signal;
|
||||
use crate::signal::RawSignal;
|
||||
use crate::{err_fmt, err_str, function};
|
||||
use nix::unistd::getpid;
|
||||
use std::sync::Arc;
|
||||
@@ -130,7 +130,7 @@ fn add_named_argument(
|
||||
opts.description = w.woptarg.unwrap().to_owned();
|
||||
}
|
||||
's' => {
|
||||
let Some(signal) = Signal::parse(w.woptarg.unwrap()) else {
|
||||
let Some(signal) = RawSignal::parse(w.woptarg.unwrap()) else {
|
||||
err_fmt!("Unknown signal '%s'", w.woptarg.unwrap())
|
||||
.cmd(cmd)
|
||||
.finish(streams);
|
||||
|
||||
4
src/env/var.rs
vendored
4
src/env/var.rs
vendored
@@ -1,4 +1,4 @@
|
||||
use crate::signal::Signal;
|
||||
use crate::signal::RawSignal;
|
||||
use bitflags::bitflags;
|
||||
use fish_common::assert_sorted_by_name;
|
||||
use fish_wcstringutil::join_strings;
|
||||
@@ -85,7 +85,7 @@ pub struct Statuses {
|
||||
|
||||
/// Signal from the most recent process in the last job that was terminated by a signal.
|
||||
/// None if all processes exited normally.
|
||||
pub kill_signal: Option<Signal>,
|
||||
pub kill_signal: Option<RawSignal>,
|
||||
|
||||
/// Pipestatus value.
|
||||
pub pipestatus: Vec<c_int>,
|
||||
|
||||
10
src/event.rs
10
src/event.rs
@@ -12,7 +12,7 @@
|
||||
prelude::*,
|
||||
proc::{InternalJobId, Pid},
|
||||
reader::reader_update_termsize,
|
||||
signal::{Signal, signal_check_cancel, signal_handle},
|
||||
signal::{RawSignal, signal_check_cancel, signal_handle},
|
||||
};
|
||||
use fish_common::{ScopeGuard, escape};
|
||||
use fish_widestring::str2wcstring;
|
||||
@@ -37,7 +37,7 @@ pub enum EventDescription {
|
||||
/// well).
|
||||
Any,
|
||||
/// An event triggered by a signal.
|
||||
Signal { signal: Signal },
|
||||
Signal { signal: RawSignal },
|
||||
/// An event triggered by a variable update.
|
||||
Variable { name: WString },
|
||||
/// An event triggered by a process exit.
|
||||
@@ -357,13 +357,13 @@ pub fn acquire_pending(&self) -> u64 {
|
||||
/// temporarily moved here. There was no mutex around this in the cpp code. TODO: Move it back.
|
||||
static BLOCKED_EVENTS: Mutex<Vec<Event>> = Mutex::new(Vec::new());
|
||||
|
||||
fn inc_signal_observed(sig: Signal) {
|
||||
fn inc_signal_observed(sig: RawSignal) {
|
||||
if let Some(sig) = OBSERVED_SIGNALS.get(usize::from(sig)) {
|
||||
sig.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
fn dec_signal_observed(sig: Signal) {
|
||||
fn dec_signal_observed(sig: RawSignal) {
|
||||
if let Some(sig) = OBSERVED_SIGNALS.get(usize::from(sig)) {
|
||||
sig.fetch_sub(1, Ordering::Relaxed);
|
||||
}
|
||||
@@ -548,7 +548,7 @@ pub fn fire_delayed(parser: &mut Parser) {
|
||||
while signals != 0 {
|
||||
let sig = signals.trailing_zeros() as i32;
|
||||
signals &= !(1_u64 << sig);
|
||||
let sig = Signal::new(sig);
|
||||
let sig = RawSignal::new(sig);
|
||||
|
||||
// HACK: The only variables we change in response to a *signal* are $COLUMNS and $LINES.
|
||||
// Do that now.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::global_safety::RelaxedAtomicBool;
|
||||
use crate::prelude::*;
|
||||
use crate::proc::{JobGroupRef, Pid};
|
||||
use crate::signal::Signal;
|
||||
use crate::signal::RawSignal;
|
||||
use nix::sys::termios::Termios;
|
||||
use std::cell::RefCell;
|
||||
use std::num::NonZeroU32;
|
||||
@@ -118,15 +118,15 @@ pub fn has_job_id(&self) -> bool {
|
||||
}
|
||||
|
||||
/// Gets the cancellation signal, if any.
|
||||
pub fn get_cancel_signal(&self) -> Option<Signal> {
|
||||
pub fn get_cancel_signal(&self) -> Option<RawSignal> {
|
||||
match self.signal.load(Ordering::Relaxed) {
|
||||
0 => None,
|
||||
s => Some(Signal::new(s)),
|
||||
s => Some(RawSignal::new(s)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Mark that a process in this group got a signal and should cancel.
|
||||
pub fn cancel_with_signal(&self, signal: Signal) {
|
||||
pub fn cancel_with_signal(&self, signal: RawSignal) {
|
||||
// We only assign the signal if one hasn't yet been assigned. This means the first signal to
|
||||
// register wins over any that come later.
|
||||
self.signal
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
},
|
||||
reader::fish_is_unwinding_for_exit,
|
||||
redirection::{RedirectionMode, RedirectionSpec, RedirectionSpecList},
|
||||
signal::Signal,
|
||||
signal::RawSignal,
|
||||
timer::push_timer,
|
||||
tokenizer::{PipeOrRedir, TokenType, variable_assignment_equals_pos},
|
||||
trace::{trace_if_enabled, trace_if_enabled_with_args},
|
||||
@@ -85,7 +85,7 @@ pub struct ExecutionContext {
|
||||
|
||||
// If set, one of our processes received a cancellation signal (INT or QUIT) so we are
|
||||
// unwinding.
|
||||
cancel_signal: Option<Signal>,
|
||||
cancel_signal: Option<RawSignal>,
|
||||
|
||||
/// The block IO chain.
|
||||
/// For example, in `begin; foo ; end < file.txt` this would have the 'file.txt' IO.
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
parse_tree::{NodeRef, ParsedSourceRef, SourceLineCache, parse_source},
|
||||
prelude::*,
|
||||
proc::{InternalJobId, JobGroupRef, JobList, JobRef, Pid, ProcStatus, job_reap},
|
||||
signal::{Signal, signal_check_cancel, signal_clear_cancel},
|
||||
signal::{RawSignal, signal_check_cancel, signal_clear_cancel},
|
||||
wait_handle::WaitHandleStore,
|
||||
};
|
||||
use assert_matches::assert_matches;
|
||||
@@ -637,7 +637,7 @@ pub fn eval_node<T: Node>(
|
||||
if self.cancel_behavior == CancelBehavior::Clear && self.block_list.is_empty() {
|
||||
signal_clear_cancel();
|
||||
} else {
|
||||
return EvalRes::new(ProcStatus::from_signal(Signal::new(sig)));
|
||||
return EvalRes::new(ProcStatus::from_signal(RawSignal::new(sig)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -649,7 +649,7 @@ pub fn eval_node<T: Node>(
|
||||
// Did fish itself get a signal?
|
||||
let sig = signal_check_cancel();
|
||||
if sig != 0 {
|
||||
return Some(Signal::new(sig));
|
||||
return Some(RawSignal::new(sig));
|
||||
}
|
||||
// Has this job group been cancelled?
|
||||
jg.as_ref().and_then(|jg| jg.get_cancel_signal())
|
||||
@@ -698,7 +698,7 @@ pub fn eval_node<T: Node>(
|
||||
|
||||
let sig = signal_check_cancel();
|
||||
if sig != 0 {
|
||||
EvalRes::new(ProcStatus::from_signal(Signal::new(sig)))
|
||||
EvalRes::new(ProcStatus::from_signal(RawSignal::new(sig)))
|
||||
} else {
|
||||
let status = ProcStatus::from_exit_code(self.last_status());
|
||||
let break_expand = reason == EndExecutionReason::Error;
|
||||
|
||||
10
src/proc.rs
10
src/proc.rs
@@ -17,7 +17,7 @@
|
||||
prelude::*,
|
||||
reader::{fish_is_unwinding_for_exit, reader_schedule_prompt_repaint},
|
||||
redirection::RedirectionSpecList,
|
||||
signal::{Signal, signal_set_handlers_once},
|
||||
signal::{RawSignal, signal_set_handlers_once},
|
||||
topic_monitor::{GenerationsList, Topic, topic_monitor_principal},
|
||||
wait_handle::{WaitHandle, WaitHandleRef, WaitHandleStore},
|
||||
wutil::{perror_nix, wbasename},
|
||||
@@ -173,7 +173,7 @@ pub fn from_exit_code(ret: i32) -> ProcStatus {
|
||||
}
|
||||
|
||||
/// Construct directly from a signal.
|
||||
pub fn from_signal(signal: Signal) -> ProcStatus {
|
||||
pub fn from_signal(signal: RawSignal) -> ProcStatus {
|
||||
ProcStatus::new(Some(Self::w_exitcode(0 /* ret */, signal.code())))
|
||||
}
|
||||
|
||||
@@ -911,7 +911,7 @@ pub fn statuses(&self) -> Option<Statuses> {
|
||||
continue;
|
||||
}
|
||||
if status.signal_exited() {
|
||||
st.kill_signal = Some(Signal::new(status.signal_code()));
|
||||
st.kill_signal = Some(RawSignal::new(status.signal_code()));
|
||||
}
|
||||
laststatus = status.status_value();
|
||||
has_status = true;
|
||||
@@ -1105,7 +1105,7 @@ fn handle_child_status(job: &Job, proc: &Process, status: ProcStatus) {
|
||||
if [SIGINT, SIGQUIT].contains(&sig) {
|
||||
if is_interactive_session() {
|
||||
// Mark the job group as cancelled.
|
||||
job.group().cancel_with_signal(Signal::new(sig));
|
||||
job.group().cancel_with_signal(RawSignal::new(sig));
|
||||
} else if !event::is_signal_observed(sig) {
|
||||
// Deliver the SIGINT or SIGQUIT signal to ourself since we're not interactive.
|
||||
let act =
|
||||
@@ -1475,7 +1475,7 @@ fn summary_command(j: &Job, p: Option<&Process>) -> WString {
|
||||
Some(p) => {
|
||||
// We are summarizing a process which exited with a signal.
|
||||
// Arguments are the signal name and description.
|
||||
let sig = Signal::new(p.status().signal_code());
|
||||
let sig = RawSignal::new(p.status().signal_code());
|
||||
buffer.push(' ');
|
||||
buffer += &escape(sig.name())[..];
|
||||
|
||||
|
||||
@@ -251,7 +251,7 @@ pub fn signal_set_handlers_once(interactive: bool) {
|
||||
}
|
||||
|
||||
/// Mark that a signal is being handled.
|
||||
pub fn signal_handle(sig: Signal) {
|
||||
pub fn signal_handle(sig: RawSignal) {
|
||||
let sig = sig.code();
|
||||
let mut act: libc::sigaction = unsafe { std::mem::zeroed() };
|
||||
|
||||
@@ -340,7 +340,7 @@ pub fn wait(&self) {
|
||||
/// Struct describing an entry for the lookup table used to convert between signal names and signal
|
||||
/// ids, etc.
|
||||
struct LookupEntry {
|
||||
signal: Signal,
|
||||
signal: RawSignal,
|
||||
name: &'static wstr,
|
||||
desc: LocalizableString, // Note: this needs to be localized via gettext before presenting it to the user.
|
||||
}
|
||||
@@ -348,7 +348,7 @@ struct LookupEntry {
|
||||
impl LookupEntry {
|
||||
const fn new(signal: i32, name: &'static wstr, desc: LocalizableString) -> Self {
|
||||
Self {
|
||||
signal: Signal::new(signal),
|
||||
signal: RawSignal::new(signal),
|
||||
name,
|
||||
desc,
|
||||
}
|
||||
@@ -472,15 +472,15 @@ fn match_signal_name(canonical: &wstr, mut name: &wstr) -> bool {
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
|
||||
/// A wrapper around the system signal code.
|
||||
pub struct Signal(NonZeroI32);
|
||||
pub struct RawSignal(NonZeroI32);
|
||||
|
||||
impl Signal {
|
||||
impl RawSignal {
|
||||
/// Creates a new `Signal` to represent the passed system signal code `sig`.
|
||||
/// Panics if `sig` is zero.
|
||||
pub const fn new(sig: i32) -> Self {
|
||||
match NonZeroI32::new(sig) {
|
||||
None => panic!("Invalid zero signal value!"),
|
||||
Some(result) => Signal(result),
|
||||
Some(result) => RawSignal(result),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ pub fn code(&self) -> i32 {
|
||||
/// recognized, `None` is returned.
|
||||
/// This also accepts integer codes via fish_wcstoi().
|
||||
/// Previously sig2wcs().
|
||||
pub fn parse(name: &wstr) -> Option<Signal> {
|
||||
pub fn parse(name: &wstr) -> Option<RawSignal> {
|
||||
for entry in SIGNAL_TABLE.iter() {
|
||||
if match_signal_name(entry.name, name) {
|
||||
return Some(entry.signal);
|
||||
@@ -526,7 +526,7 @@ pub fn parse(name: &wstr) -> Option<Signal> {
|
||||
|
||||
if let Ok(num) = fish_wcstoi(name) {
|
||||
if num > 0 {
|
||||
return Some(Signal::new(num));
|
||||
return Some(RawSignal::new(num));
|
||||
}
|
||||
}
|
||||
None
|
||||
@@ -534,58 +534,58 @@ pub fn parse(name: &wstr) -> Option<Signal> {
|
||||
}
|
||||
|
||||
// Allow signals to be compared against i32.
|
||||
impl PartialEq<i32> for Signal {
|
||||
impl PartialEq<i32> for RawSignal {
|
||||
fn eq(&self, other: &i32) -> bool {
|
||||
self.code() == *other
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Signal> for i32 {
|
||||
fn from(value: Signal) -> Self {
|
||||
impl From<RawSignal> for i32 {
|
||||
fn from(value: RawSignal) -> Self {
|
||||
value.code()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Signal> for usize {
|
||||
fn from(value: Signal) -> Self {
|
||||
impl From<RawSignal> for usize {
|
||||
fn from(value: RawSignal) -> Self {
|
||||
usize::try_from(value.code()).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Signal> for NonZeroI32 {
|
||||
fn from(value: Signal) -> Self {
|
||||
impl From<RawSignal> for NonZeroI32 {
|
||||
fn from(value: RawSignal) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Signal;
|
||||
use super::RawSignal;
|
||||
use crate::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn test_signal_name() {
|
||||
let sig = Signal::new(libc::SIGINT);
|
||||
let sig = RawSignal::new(libc::SIGINT);
|
||||
assert_eq!(sig.name(), "SIGINT");
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[test]
|
||||
fn test_signal_parse() {
|
||||
assert_eq!(Signal::parse(L!("SIGHUP")), Some(Signal::new(libc::SIGHUP)));
|
||||
assert_eq!(Signal::parse(L!("sigwinch")), Some(Signal::new(libc::SIGWINCH)));
|
||||
assert_eq!(Signal::parse(L!("TSTP")), Some(Signal::new(libc::SIGTSTP)));
|
||||
assert_eq!(Signal::parse(L!("TstP")), Some(Signal::new(libc::SIGTSTP)));
|
||||
assert_eq!(Signal::parse(L!("sigCONT")), Some(Signal::new(libc::SIGCONT)));
|
||||
assert_eq!(Signal::parse(L!("SIGFOO")), None);
|
||||
assert_eq!(Signal::parse(L!("")), None);
|
||||
assert_eq!(Signal::parse(L!("SIG")), None);
|
||||
assert_eq!(Signal::parse(L!("سلام")), None);
|
||||
assert_eq!(RawSignal::parse(L!("SIGHUP")), Some(RawSignal::new(libc::SIGHUP)));
|
||||
assert_eq!(RawSignal::parse(L!("sigwinch")), Some(RawSignal::new(libc::SIGWINCH)));
|
||||
assert_eq!(RawSignal::parse(L!("TSTP")), Some(RawSignal::new(libc::SIGTSTP)));
|
||||
assert_eq!(RawSignal::parse(L!("TstP")), Some(RawSignal::new(libc::SIGTSTP)));
|
||||
assert_eq!(RawSignal::parse(L!("sigCONT")), Some(RawSignal::new(libc::SIGCONT)));
|
||||
assert_eq!(RawSignal::parse(L!("SIGFOO")), None);
|
||||
assert_eq!(RawSignal::parse(L!("")), None);
|
||||
assert_eq!(RawSignal::parse(L!("SIG")), None);
|
||||
assert_eq!(RawSignal::parse(L!("سلام")), None);
|
||||
|
||||
assert_eq!(Signal::parse(&libc::SIGINT.to_wstring()), Some(Signal::new(libc::SIGINT)));
|
||||
assert_eq!(Signal::parse(L!("0")), None);
|
||||
assert_eq!(Signal::parse(L!("-0")), None);
|
||||
assert_eq!(Signal::parse(L!("-1")), None);
|
||||
assert_eq!(RawSignal::parse(&libc::SIGINT.to_wstring()), Some(RawSignal::new(libc::SIGINT)));
|
||||
assert_eq!(RawSignal::parse(L!("0")), None);
|
||||
assert_eq!(RawSignal::parse(L!("-0")), None);
|
||||
assert_eq!(RawSignal::parse(L!("-1")), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user