diff --git a/pkg/sentry/fsimpl/devpts/line_discipline.go b/pkg/sentry/fsimpl/devpts/line_discipline.go index 4b0f3fd3b..266cfbab3 100644 --- a/pkg/sentry/fsimpl/devpts/line_discipline.go +++ b/pkg/sentry/fsimpl/devpts/line_discipline.go @@ -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 diff --git a/pkg/sentry/fsimpl/devpts/terminal.go b/pkg/sentry/fsimpl/devpts/terminal.go index d9e0164a6..6c153f9c8 100644 --- a/pkg/sentry/fsimpl/devpts/terminal.go +++ b/pkg/sentry/fsimpl/devpts/terminal.go @@ -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 }