1 extern crate nix;
2 
3 use nix::fcntl::OFlag;
4 use nix::pty::*;
5 use nix::unistd::close;
6 use std::os::unix::io::AsRawFd;
7 
8 /// Regression test for Issue #659
9 /// `PtyMaster` should panic rather than double close the file descriptor
10 /// This must run in its own test process because it deliberately creates a race
11 /// condition.
12 #[test]
13 #[should_panic(expected = "Closing an invalid file descriptor!")]
14 // In Travis on i686-unknown-linux-musl, this test gets SIGABRT.  I don't know
15 // why.  It doesn't happen on any other target, and it doesn't happen on my PC.
16 #[cfg_attr(all(target_env = "musl", target_arch = "x86"), ignore)]
test_double_close()17 fn test_double_close() {
18     let m = posix_openpt(OFlag::O_RDWR).unwrap();
19     close(m.as_raw_fd()).unwrap();
20     drop(m);            // should panic here
21 }
22