Skip to content

Commit

Permalink
修复tty处理信号时错误地将前台进程组置空的问题 & clone时未拷贝父进程tty的问题 (DragonOS-Community#1043)
Browse files Browse the repository at this point in the history
* 修复clone时未拷贝父进程tty的问题

* 修复tty处理信号时错误地将前台进程组置空的问题
  • Loading branch information
MemoryShore authored and BrahmaMantra committed Dec 9, 2024
1 parent e3d3744 commit 74479eb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 1 addition & 3 deletions kernel/src/driver/tty/tty_ldisc/ntty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,14 +785,12 @@ impl NTtyData {
signal: Signal,
) {
// 先处理信号
let mut ctrl_info = tty.core().contorl_info_irqsave();
let ctrl_info = tty.core().contorl_info_irqsave();
let pg = ctrl_info.pgid;
if let Some(pg) = pg {
let _ = Syscall::kill(pg, signal as i32);
}

ctrl_info.pgid = None;

if !termios.local_mode.contains(LocalMode::NOFLSH) {
// 重置
self.echo_head = 0;
Expand Down
5 changes: 0 additions & 5 deletions kernel/src/process/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ impl ProcessManager {

let pcb = ProcessControlBlock::new(name, new_kstack);

// TODO: 注意!这里设置tty的操作不符合Linux的行为!(毕竟创建进程不一定要fork,也可以用clone来创建)
// 正确做法应该是在实现进程组之后去管理前台进程组。
pcb.sig_info_mut()
.set_tty(current_pcb.sig_info_irqsave().tty());

let mut args = KernelCloneArgs::new();
args.flags = clone_flags;
args.exit_signal = Signal::SIGCHLD;
Expand Down
9 changes: 6 additions & 3 deletions kernel/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,16 +705,17 @@ impl ProcessControlBlock {

#[inline(never)]
fn do_create_pcb(name: String, kstack: KernelStack, is_idle: bool) -> Arc<Self> {
let (pid, ppid, cwd, cred) = if is_idle {
let (pid, ppid, cwd, cred, tty) = if is_idle {
let cred = INIT_CRED.clone();
(Pid(0), Pid(0), "/".to_string(), cred)
(Pid(0), Pid(0), "/".to_string(), cred, None)
} else {
let ppid = ProcessManager::current_pcb().pid();
let mut cred = ProcessManager::current_pcb().cred();
cred.cap_permitted = cred.cap_ambient;
cred.cap_effective = cred.cap_ambient;
let cwd = ProcessManager::current_pcb().basic().cwd();
(Self::generate_pid(), ppid, cwd, cred)
let tty = ProcessManager::current_pcb().sig_info_irqsave().tty();
(Self::generate_pid(), ppid, cwd, cred, tty)
};

let basic_info = ProcessBasicInfo::new(Pid(0), ppid, Pid(0), name, cwd, None);
Expand Down Expand Up @@ -754,6 +755,8 @@ impl ProcessControlBlock {
cred: SpinLock::new(cred),
};

pcb.sig_info.write().set_tty(tty);

// 初始化系统调用栈
#[cfg(target_arch = "x86_64")]
pcb.arch_info
Expand Down

0 comments on commit 74479eb

Please sign in to comment.