Support some PTY control characters

This commit is contained in:
Wim
2023-02-19 17:08:17 +01:00
parent c020e2de83
commit a547fffe1e
2 changed files with 15 additions and 0 deletions
@@ -111,6 +111,10 @@ 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
}
func newLineDiscipline(termios linux.KernelTermios) *lineDiscipline {
@@ -120,6 +124,10 @@ func newLineDiscipline(termios linux.KernelTermios) *lineDiscipline {
return &ld
}
func (l *lineDiscipline) SetForegroundProcessGroup(pg *kernel.ProcessGroup) {
l.fgProcessGroup = pg
}
// getTermios gets the linux.Termios for the tty.
func (l *lineDiscipline) getTermios(task *kernel.Task, args arch.SyscallArguments) (uintptr, error) {
l.termiosMu.RLock()
@@ -393,6 +401,10 @@ func (*inputQueueTransformer) transform(l *lineDiscipline, q *queue, buf []byte)
if l.termios.IEnabled(linux.INLCR) {
cBytes[0] = '\r'
}
case l.termios.ControlCharacters[linux.VINTR]: // ctrl-c
l.fgProcessGroup.SendSignal(kernel.SignalInfoPriv(linux.SIGINT))
case l.termios.ControlCharacters[linux.VSUSP]: // ctrl-z
l.fgProcessGroup.SendSignal(kernel.SignalInfoPriv(linux.SIGTSTP))
}
// In canonical mode, we discard non-terminating characters
+3
View File
@@ -105,6 +105,9 @@ 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())
ret, err := task.ThreadGroup().SetForegroundProcessGroup(tm.tty(isMaster), kernel.ProcessGroupID(pgid))
return uintptr(ret), err
}