Skip to content

Commit 1fe874f

Browse files
committed
sys::pty fix test_read_ptty_pair for solarish.
While the test_write_ptty_pair passes, the test_read_ptty_pair fails when filling the master buffer. Thus, we disable canonical and echo modes on the slave.
1 parent 1df1069 commit 1fe874f

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

test/test_pty.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ fn open_ptty_pair() -> (PtyMaster, File) {
8484
let _m = crate::PTSNAME_MTX.lock();
8585

8686
// Open a new PTTY master
87-
let master = posix_openpt(OFlag::O_RDWR).expect("posix_openpt failed");
87+
let master = posix_openpt(OFlag::O_RDWR | OFlag::O_NOCTTY)
88+
.expect("posix_openpt failed");
8889

8990
// Allow a slave to be generated for it
9091
grantpt(&master).expect("grantpt failed");
@@ -94,9 +95,12 @@ fn open_ptty_pair() -> (PtyMaster, File) {
9495
let slave_name = unsafe { ptsname(&master) }.expect("ptsname failed");
9596

9697
// Open the slave device
97-
let slave_fd =
98-
open(Path::new(&slave_name), OFlag::O_RDWR, stat::Mode::empty())
99-
.unwrap();
98+
let slave_fd = open(
99+
Path::new(&slave_name),
100+
OFlag::O_RDWR | OFlag::O_NOCTTY,
101+
stat::Mode::empty(),
102+
)
103+
.unwrap();
100104

101105
#[cfg(solarish)]
102106
// TODO: rewrite using ioctl!
@@ -123,6 +127,19 @@ fn open_ptty_pair() -> (PtyMaster, File) {
123127

124128
let slave = unsafe { File::from_raw_fd(slave_fd) };
125129

130+
#[cfg(solarish)]
131+
{
132+
use nix::sys::termios::{
133+
tcgetattr, tcsetattr, LocalFlags, SetArg, SpecialCharacterIndices,
134+
};
135+
let mut tty = tcgetattr(&slave).expect("tcgetattr failed");
136+
tty.local_flags &= LocalFlags::ICANON | LocalFlags::ECHO;
137+
tty.control_chars[SpecialCharacterIndices::VMIN as usize] = 1;
138+
tty.control_chars[SpecialCharacterIndices::VTIME as usize] = 0;
139+
140+
tcsetattr(&slave, SetArg::TCSANOW, &tty).expect("tcsetattr failed");
141+
}
142+
126143
(master, slave)
127144
}
128145

0 commit comments

Comments
 (0)