TIOCSCTTY has to succeed if a specified tty is a controlling one already

This behavior isn't documented in the tty_ioctl man,
but it is in the kernel for ages.

PiperOrigin-RevId: 577097643
This commit is contained in:
Andrei Vagin
2023-10-26 23:57:42 -07:00
committed by gVisor bot
parent aa02c6fa15
commit b357d71828
2 changed files with 8 additions and 1 deletions
+6 -1
View File
@@ -376,7 +376,12 @@ func (tg *ThreadGroup) SetControllingTTY(tty *TTY, steal bool, isReadable bool)
// "The calling process must be a session leader and not have a
// controlling terminal already." - tty_ioctl(4)
if tg.processGroup.session.leader != tg || tg.tty != nil {
if tg.processGroup.session.leader != tg {
return linuxerr.EINVAL
}
if tg.tty == tty {
return nil
} else if tg.tty != nil {
return linuxerr.EINVAL
}
+2
View File
@@ -1476,6 +1476,8 @@ TEST_F(JobControlTest, SetTTY) {
auto res = RunInChild([=]() {
TEST_PCHECK(setsid() >= 0);
TEST_PCHECK(ioctl(!replica_.get(), TIOCSCTTY, 0));
// The second attempt setting the same terminal has to be no-op.
TEST_PCHECK(ioctl(!replica_.get(), TIOCSCTTY, 0));
});
ASSERT_NO_ERRNO(res);
}