diff --git a/cykusz-rs/src/drivers/tty/mod.rs b/cykusz-rs/src/drivers/tty/mod.rs index a21365d1..c842d16d 100644 --- a/cykusz-rs/src/drivers/tty/mod.rs +++ b/cykusz-rs/src/drivers/tty/mod.rs @@ -19,7 +19,7 @@ use crate::kernel::kbd::KeyListener; use crate::kernel::mm::VirtAddr; use crate::kernel::sched::current_task_ref; use crate::kernel::session::{sessions, Group}; -use crate::kernel::signal::SignalResult; +use crate::kernel::signal::{SignalError, SignalResult}; use crate::kernel::sync::{Spin, SpinGuard}; use crate::kernel::task::Task; @@ -125,6 +125,14 @@ impl Tty { } fn read(&self, buf: *mut u8, len: usize) -> SignalResult<usize> { + if let Some(fg) = &*self.fg_group.lock_irq() { + let task = current_task_ref(); + + if !fg.has_process(task.pid()) { + task.signal(syscall_defs::signal::SIGTTIN); + return Err(SignalError::Interrupted); + } + } let mut buffer = self .wait_queue .wait_lock_for(WaitQueueFlags::IRQ_DISABLE, &self.buffer, |lck| { @@ -571,6 +579,15 @@ impl INode for Tty { let termios = unsafe { VirtAddr(arg).read_ref::<syscall_defs::ioctl::tty::Termios>() }; + if let Some(fg) = &*self.fg_group.lock_irq() { + let task = current_task_ref(); + + if !fg.has_process(task.pid()) { + task.signal(syscall_defs::signal::SIGTTOU); + return Err(FsError::Interrupted); + } + } + logln3!("termios TCSETS 0x{:x}", termios.c_lflag); logln3!("{:?}", termios); diff --git a/cykusz-rs/src/kernel/signal/default.rs b/cykusz-rs/src/kernel/signal/default.rs index da53a93d..a7c3b49a 100644 --- a/cykusz-rs/src/kernel/signal/default.rs +++ b/cykusz-rs/src/kernel/signal/default.rs @@ -30,8 +30,8 @@ static DEFAULT_ACTIONS: [Action; super::SIGNAL_COUNT] = [ Action::Ignore, // SIGCONT Action::Handle(stop), // SIGSTOP Action::Handle(stop), // SIGTSTP - Action::Ignore, // UNUSED - Action::Ignore, // UNUSED + Action::Handle(stop), // SIGTTIN + Action::Handle(stop), // SIGTTOU Action::Ignore, // UNUSED Action::Ignore, // UNUSED Action::Ignore, // UNUSED diff --git a/syscall-defs/src/signal.rs b/syscall-defs/src/signal.rs index c5630add..36d55024 100644 --- a/syscall-defs/src/signal.rs +++ b/syscall-defs/src/signal.rs @@ -13,6 +13,8 @@ pub const SIGCHLD: usize = 17; pub const SIGCONT: usize = 18; pub const SIGSTOP: usize = 19; pub const SIGTSTP: usize = 20; +pub const SIGTTIN: usize = 21; +pub const SIGTTOU: usize = 22; #[derive(Debug, Copy, Clone, PartialEq)] pub enum SignalHandler {