Clean up tty.CheckChange and call it in SetForegroundProcessGroup.

Previously, CheckChange (corresponding to Linux's tty/tty_check_change()) was
only used the host TTY implementation, not the devpts implementation.

Furthermore, ThreadGroup.SetForegroundProcessGroup() duplicated some of the
logic in CheckChange, notably sending SIGTTOU to background tasks. This means
that, for host TTYs, we could send SIGTTOU multiple times. In some
circumstances, this leads the ioctl returning ERESTARTSYS in an infinite loop.

PiperOrigin-RevId: 735934036
This commit is contained in:
Nicolas Lacasse
2025-03-11 16:46:55 -07:00
committed by gVisor bot
parent 93536059ca
commit f9b1ce2f7d
5 changed files with 89 additions and 101 deletions
+1 -1
View File
@@ -198,7 +198,7 @@ func (mfd *masterFileDescription) Ioctl(ctx context.Context, io usermem.IO, sysn
if _, err := pgid.CopyIn(t, args[2].Pointer()); err != nil {
return 0, err
}
return 0, t.ThreadGroup().SetForegroundProcessGroupID(mfd.t.masterKTTY, kernel.ProcessGroupID(pgid))
return 0, t.ThreadGroup().SetForegroundProcessGroupID(ctx, mfd.t.masterKTTY, kernel.ProcessGroupID(pgid))
default:
maybeEmitUnimplementedEvent(ctx, sysno, cmd)
return 0, linuxerr.ENOTTY
+1 -1
View File
@@ -188,7 +188,7 @@ func (rfd *replicaFileDescription) Ioctl(ctx context.Context, io usermem.IO, sys
if _, err := pgid.CopyIn(t, args[2].Pointer()); err != nil {
return 0, err
}
return 0, t.ThreadGroup().SetForegroundProcessGroupID(rfd.inode.t.replicaKTTY, kernel.ProcessGroupID(pgid))
return 0, t.ThreadGroup().SetForegroundProcessGroupID(ctx, rfd.inode.t.replicaKTTY, kernel.ProcessGroupID(pgid))
default:
maybeEmitUnimplementedEvent(ctx, sysno, cmd)
return 0, linuxerr.ENOTTY