Skip to content

Commit

Permalink
tty: Send SIGTTIN SIGTTOU on write/read to tty by background process
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalmiel committed Oct 19, 2023
1 parent 983b41c commit bf6e167
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
19 changes: 18 additions & 1 deletion cykusz-rs/src/drivers/tty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions cykusz-rs/src/kernel/signal/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions syscall-defs/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bf6e167

Please sign in to comment.