Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions kernel/src/ipc/sighand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ impl SigHand {
g.flags.remove(flag);
}

pub fn flags_test_and_clear(&self, flag: SignalFlags, clear: bool) -> bool {
let mut g = self.inner_mut();
if !g.flags.contains(flag) {
return false;
}
if clear {
g.flags.remove(flag);
}
true
}

pub fn stop_signal(&self) -> Signal {
self.inner().stop_signal
}
Expand Down Expand Up @@ -450,11 +461,11 @@ fn default_sighandlers() -> Vec<Sigaction> {
let mut r = vec![Sigaction::default(); MAX_SIG_NUM];
let mut sig_ign = Sigaction::default();
// 收到忽略的信号,重启系统调用
// Linux 对 SIGCHLD/SIGURG/SIGWINCH 默认忽略;这里显式设置 Ignore
// Linux ignores SIGURG/SIGWINCH by default; SIGCHLD is also ignored by default,
// but the handler must remain SIG_DFL to distinguish default ignore from explicit SIG_IGN.
sig_ign.set_action(SigactionType::SaHandler(SaHandlerType::Ignore));
sig_ign.flags_mut().insert(SigFlags::SA_RESTART);

r[Signal::SIGCHLD as usize - 1] = sig_ign;
r[Signal::SIGURG as usize - 1] = sig_ign;
r[Signal::SIGWINCH as usize - 1] = sig_ign;

Expand Down
29 changes: 1 addition & 28 deletions kernel/src/ipc/syscall/sys_kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum PidConverter {
}

impl PidConverter {
/// ### 为 `wait` 和 `kill` 调用使用
/// ### For `kill` syscall use
pub fn from_id(id: i32) -> Option<Self> {
if id < -1 {
let pgid = ProcessManager::find_vpid(RawPid::from(-id as usize));
Expand All @@ -46,33 +46,6 @@ impl PidConverter {
Some(PidConverter::Pid(pid))
}
}

/// ### 为 `waitid` 使用:which/upid 已在封装层基本校验
/// 约定:which: 0=P_ALL, 1=P_PID(id>0), 2=P_PGID(id>=0; 0=当前组)
pub fn from_waitid(which: u32, upid: i32) -> Option<Self> {
match which {
0 => Some(PidConverter::All),
1 => {
if upid <= 0 {
return None;
}
Self::from_id(upid)
}
2 => {
if upid < 0 {
return None;
}
// P_PGID: upid==0 -> 当前进程组;>0 -> 指定pgid
// from_id: id< -1 为 pgid,因此这里将正 pgid 映射为负数传入
if upid == 0 {
Self::from_id(0)
} else {
Self::from_id(-upid)
}
}
_ => None,
}
}
}

/// Check if the current process has permission to send a signal to the target process.
Expand Down
Loading
Loading