mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user