Skip to content

Commit

Permalink
tty: support setting controlling session
Browse files Browse the repository at this point in the history
This is... kinda backwards? But it works sufficiently for us.
Every TTY has at most one controlling session - every session
is supposed have at most one controlling terminal, too, but we
don't implement that part yet.
  • Loading branch information
klange committed Jan 19, 2024
1 parent 0d28bf0 commit fa8a6e2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions kernel/vfs/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,24 @@ int pty_ioctl(pty_t * pty, unsigned long request, void * argp) {
validate(argp);
*(pid_t *)argp = pty->fg_proc;
return 0;
case TIOCSCTTY:
/* If this is already the control session, quietly ignore. */
if (this_core->current_process->session == this_core->current_process->id &&
pty->ct_proc == this_core->current_process->session) {
return 0;
}
/* If we aren't a session leader, we can't do this. */
if (this_core->current_process->session != this_core->current_process->id) {
return -EPERM;
}
/* If there's already a control session, only root can steal control, and only if *argp is 1
* (on Linux, that's "if argp is 1", but we kinda messed this up by checking ioctl argp stuff
* for bounds validity in the system call layer, so instead we use a pointer to 1... */
if (pty->ct_proc && (!argp || (*(int*)argp != 1) || this_core->current_process->user != 0)) {
return -EPERM;
}
pty->ct_proc = this_core->current_process->session;
return 0;
case TCSETS:
case TCSETSW:
if (!argp) return -EINVAL;
Expand Down

0 comments on commit fa8a6e2

Please sign in to comment.