Add reference to terminal in lineDiscipline

This commit is contained in:
Wim
2023-02-22 22:33:37 +01:00
parent 56458440b3
commit 1dc92a8c71
2 changed files with 14 additions and 10 deletions
+7 -8
View File
@@ -112,9 +112,8 @@ type lineDiscipline struct {
// replicaWaiter is used to wait on the replica end of the TTY.
replicaWaiter waiter.Queue
// fgProcessGroup is the foreground process group that is currently
// connected to this TTY.
fgProcessGroup *kernel.ProcessGroup
// terminal is the terminal linked to this lineDiscipline
terminal *Terminal
}
func newLineDiscipline(termios linux.KernelTermios) *lineDiscipline {
@@ -124,8 +123,8 @@ func newLineDiscipline(termios linux.KernelTermios) *lineDiscipline {
return &ld
}
func (l *lineDiscipline) SetForegroundProcessGroup(pg *kernel.ProcessGroup) {
l.fgProcessGroup = pg
func (l *lineDiscipline) SetTerminal(tm *Terminal) {
l.terminal = tm
}
// getTermios gets the linux.Termios for the tty.
@@ -402,11 +401,11 @@ func (*inputQueueTransformer) transform(l *lineDiscipline, q *queue, buf []byte)
cBytes[0] = '\r'
}
case l.termios.ControlCharacters[linux.VINTR]: // ctrl-c
l.fgProcessGroup.SendSignal(kernel.SignalInfoPriv(linux.SIGINT))
l.terminal.fgProcessGroup.SendSignal(kernel.SignalInfoPriv(linux.SIGINT))
case l.termios.ControlCharacters[linux.VSUSP]: // ctrl-z
l.fgProcessGroup.SendSignal(kernel.SignalInfoPriv(linux.SIGTSTP))
l.terminal.fgProcessGroup.SendSignal(kernel.SignalInfoPriv(linux.SIGTSTP))
case l.termios.ControlCharacters[linux.VQUIT]: // ctrl-\
l.fgProcessGroup.SendSignal(kernel.SignalInfoPriv(linux.SIGQUIT))
l.terminal.fgProcessGroup.SendSignal(kernel.SignalInfoPriv(linux.SIGQUIT))
}
// In canonical mode, we discard non-terminating characters
+7 -2
View File
@@ -39,6 +39,10 @@ type Terminal struct {
// replicaKTTY contains the controlling process of the replica end of this
// terminal. This field is immutable.
replicaKTTY *kernel.TTY
// fgProcessGroup is the foreground process group that is currently
// connected to this TTY.
fgProcessGroup *kernel.ProcessGroup
}
func newTerminal(n uint32) *Terminal {
@@ -49,6 +53,8 @@ func newTerminal(n uint32) *Terminal {
masterKTTY: &kernel.TTY{Index: n},
replicaKTTY: &kernel.TTY{Index: n},
}
t.ld.SetTerminal(&t)
return &t
}
@@ -105,8 +111,7 @@ func (tm *Terminal) setForegroundProcessGroup(ctx context.Context, args arch.Sys
return 0, err
}
// Put the processgroup also in line discipline for further signal handling
tm.ld.SetForegroundProcessGroup(task.ThreadGroup().ProcessGroup())
tm.fgProcessGroup = task.ThreadGroup().ProcessGroup()
ret, err := task.ThreadGroup().SetForegroundProcessGroup(tm.tty(isMaster), kernel.ProcessGroupID(pgid))
return uintptr(ret), err