summaryrefslogtreecommitdiffstats
path: root/third_party/rust/nix/test/test_ptymaster_drop.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/nix/test/test_ptymaster_drop.rs')
-rw-r--r--third_party/rust/nix/test/test_ptymaster_drop.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/third_party/rust/nix/test/test_ptymaster_drop.rs b/third_party/rust/nix/test/test_ptymaster_drop.rs
new file mode 100644
index 0000000000..ffbaa56977
--- /dev/null
+++ b/third_party/rust/nix/test/test_ptymaster_drop.rs
@@ -0,0 +1,20 @@
+#[cfg(not(any(target_os = "redox", target_os = "fuchsia")))]
+mod t {
+ use nix::fcntl::OFlag;
+ use nix::pty::*;
+ use nix::unistd::close;
+ use std::os::unix::io::AsRawFd;
+
+ /// Regression test for Issue #659
+ ///
+ /// `PtyMaster` should panic rather than double close the file descriptor
+ /// This must run in its own test process because it deliberately creates a
+ /// race condition.
+ #[test]
+ #[should_panic(expected = "Closing an invalid file descriptor!")]
+ fn test_double_close() {
+ let m = posix_openpt(OFlag::O_RDWR).unwrap();
+ close(m.as_raw_fd()).unwrap();
+ drop(m); // should panic here
+ }
+}