From 74479eb83b1ffd0f0e13079d9cc74bb4bf2d3111 Mon Sep 17 00:00:00 2001 From: MemoryShore <1353318529@qq.com> Date: Tue, 12 Nov 2024 16:31:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtty=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E6=97=B6=E9=94=99=E8=AF=AF=E5=9C=B0=E5=B0=86?= =?UTF-8?q?=E5=89=8D=E5=8F=B0=E8=BF=9B=E7=A8=8B=E7=BB=84=E7=BD=AE=E7=A9=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20&=20clone=E6=97=B6=E6=9C=AA?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E7=88=B6=E8=BF=9B=E7=A8=8Btty=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#1043)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复clone时未拷贝父进程tty的问题 * 修复tty处理信号时错误地将前台进程组置空的问题 --- kernel/src/driver/tty/tty_ldisc/ntty.rs | 4 +--- kernel/src/process/fork.rs | 5 ----- kernel/src/process/mod.rs | 9 ++++++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/kernel/src/driver/tty/tty_ldisc/ntty.rs b/kernel/src/driver/tty/tty_ldisc/ntty.rs index c26b3a293..df684e9d9 100644 --- a/kernel/src/driver/tty/tty_ldisc/ntty.rs +++ b/kernel/src/driver/tty/tty_ldisc/ntty.rs @@ -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; diff --git a/kernel/src/process/fork.rs b/kernel/src/process/fork.rs index bde3b0b8e..41265d139 100644 --- a/kernel/src/process/fork.rs +++ b/kernel/src/process/fork.rs @@ -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; diff --git a/kernel/src/process/mod.rs b/kernel/src/process/mod.rs index 1c5ce4bb4..9049864fb 100644 --- a/kernel/src/process/mod.rs +++ b/kernel/src/process/mod.rs @@ -705,16 +705,17 @@ impl ProcessControlBlock { #[inline(never)] fn do_create_pcb(name: String, kstack: KernelStack, is_idle: bool) -> Arc { - 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); @@ -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