mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix JobControl tests for open source.
ioctl calls with TIOCSCTTY fail if the calling process already has a controlling terminal, which occurs on a 5.4 kernel like our Ubuntu 18 CI. Thus, run tests calling ioctl TTOCSCTTY in clean subprocess. Also, while we're here, switch out non-inclusive master/slave for main/replica. PiperOrigin-RevId: 328756598
This commit is contained in:
committed by
gVisor bot
parent
32e7a54f7f
commit
140ffb6007
+397
-351
File diff suppressed because it is too large
Load Diff
@@ -48,12 +48,12 @@ TEST(JobControlRootTest, StealTTY) {
|
||||
ASSERT_THAT(setsid(), SyscallSucceeds());
|
||||
}
|
||||
|
||||
FileDescriptor master =
|
||||
FileDescriptor main =
|
||||
ASSERT_NO_ERRNO_AND_VALUE(Open("/dev/ptmx", O_RDWR | O_NONBLOCK));
|
||||
FileDescriptor slave = ASSERT_NO_ERRNO_AND_VALUE(OpenSlave(master));
|
||||
FileDescriptor replica = ASSERT_NO_ERRNO_AND_VALUE(OpenReplica(main));
|
||||
|
||||
// Make slave the controlling terminal.
|
||||
ASSERT_THAT(ioctl(slave.get(), TIOCSCTTY, 0), SyscallSucceeds());
|
||||
// Make replica the controlling terminal.
|
||||
ASSERT_THAT(ioctl(replica.get(), TIOCSCTTY, 0), SyscallSucceeds());
|
||||
|
||||
// Fork, join a new session, and try to steal the parent's controlling
|
||||
// terminal, which should succeed when we have CAP_SYS_ADMIN and pass an arg
|
||||
@@ -62,9 +62,9 @@ TEST(JobControlRootTest, StealTTY) {
|
||||
if (!child) {
|
||||
ASSERT_THAT(setsid(), SyscallSucceeds());
|
||||
// We shouldn't be able to steal the terminal with the wrong arg value.
|
||||
TEST_PCHECK(ioctl(slave.get(), TIOCSCTTY, 0));
|
||||
TEST_PCHECK(ioctl(replica.get(), TIOCSCTTY, 0));
|
||||
// We should be able to steal it if we are true root.
|
||||
TEST_PCHECK(true_root == !ioctl(slave.get(), TIOCSCTTY, 1));
|
||||
TEST_PCHECK(true_root == !ioctl(replica.get(), TIOCSCTTY, 1));
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,25 +23,25 @@
|
||||
namespace gvisor {
|
||||
namespace testing {
|
||||
|
||||
PosixErrorOr<FileDescriptor> OpenSlave(const FileDescriptor& master) {
|
||||
PosixErrorOr<int> n = SlaveID(master);
|
||||
PosixErrorOr<FileDescriptor> OpenReplica(const FileDescriptor& main) {
|
||||
PosixErrorOr<int> n = ReplicaID(main);
|
||||
if (!n.ok()) {
|
||||
return PosixErrorOr<FileDescriptor>(n.error());
|
||||
}
|
||||
return Open(absl::StrCat("/dev/pts/", n.ValueOrDie()), O_RDWR | O_NONBLOCK);
|
||||
}
|
||||
|
||||
PosixErrorOr<int> SlaveID(const FileDescriptor& master) {
|
||||
PosixErrorOr<int> ReplicaID(const FileDescriptor& main) {
|
||||
// Get pty index.
|
||||
int n;
|
||||
int ret = ioctl(master.get(), TIOCGPTN, &n);
|
||||
int ret = ioctl(main.get(), TIOCGPTN, &n);
|
||||
if (ret < 0) {
|
||||
return PosixError(errno, "ioctl(TIOCGPTN) failed");
|
||||
}
|
||||
|
||||
// Unlock pts.
|
||||
int unlock = 0;
|
||||
ret = ioctl(master.get(), TIOCSPTLCK, &unlock);
|
||||
ret = ioctl(main.get(), TIOCSPTLCK, &unlock);
|
||||
if (ret < 0) {
|
||||
return PosixError(errno, "ioctl(TIOSPTLCK) failed");
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
namespace gvisor {
|
||||
namespace testing {
|
||||
|
||||
// Opens the slave end of the passed master as R/W and nonblocking.
|
||||
PosixErrorOr<FileDescriptor> OpenSlave(const FileDescriptor& master);
|
||||
// Opens the replica end of the passed main as R/W and nonblocking.
|
||||
PosixErrorOr<FileDescriptor> OpenReplica(const FileDescriptor& main);
|
||||
|
||||
// Get the number of the slave end of the master.
|
||||
PosixErrorOr<int> SlaveID(const FileDescriptor& master);
|
||||
// Get the number of the replica end of the main.
|
||||
PosixErrorOr<int> ReplicaID(const FileDescriptor& main);
|
||||
|
||||
} // namespace testing
|
||||
} // namespace gvisor
|
||||
|
||||
Reference in New Issue
Block a user