Merge pull request #8562 from 42wim:signals

PiperOrigin-RevId: 511907546
This commit is contained in:
gVisor bot
2023-02-23 15:51:03 -08:00
2 changed files with 19 additions and 0 deletions
@@ -111,6 +111,9 @@ type lineDiscipline struct {
// replicaWaiter is used to wait on the replica end of the TTY.
replicaWaiter waiter.Queue
// terminal is the terminal linked to this lineDiscipline.
terminal *Terminal
}
func newLineDiscipline(termios linux.KernelTermios) *lineDiscipline {
@@ -393,6 +396,12 @@ 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.terminal.fgProcessGroup.SendSignal(kernel.SignalInfoPriv(linux.SIGINT))
case l.termios.ControlCharacters[linux.VSUSP]: // ctrl-z
l.terminal.fgProcessGroup.SendSignal(kernel.SignalInfoPriv(linux.SIGTSTP))
case l.termios.ControlCharacters[linux.VQUIT]: // ctrl-\
l.terminal.fgProcessGroup.SendSignal(kernel.SignalInfoPriv(linux.SIGQUIT))
}
// In canonical mode, we discard non-terminating characters
+10
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,9 @@ func newTerminal(n uint32) *Terminal {
masterKTTY: &kernel.TTY{Index: n},
replicaKTTY: &kernel.TTY{Index: n},
}
t.ld.terminal = &t
return &t
}
@@ -106,6 +113,9 @@ func (tm *Terminal) setForegroundProcessGroup(ctx context.Context, args arch.Sys
}
ret, err := task.ThreadGroup().SetForegroundProcessGroup(tm.tty(isMaster), kernel.ProcessGroupID(pgid))
if err == nil {
tm.fgProcessGroup = task.PIDNamespace().ProcessGroupWithID(kernel.ProcessGroupID(pgid))
}
return uintptr(ret), err
}