diff options
author | Alan Somers <asomers@gmail.com> | 2017-07-19 22:59:47 -0600 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2017-07-19 22:59:47 -0600 |
commit | ce04f1ce80dc3109ae27fbe5cefa6cdb52625b52 (patch) | |
tree | 1ea2e3603d051e7e5522c2d903f55968c8cad29e /test/sys/test_termios.rs | |
parent | 07e6c2f5c2d2a95fcfcd509556c4d1441a91adfb (diff) | |
download | nix-ce04f1ce80dc3109ae27fbe5cefa6cdb52625b52.zip |
Fix thread safety issues in pty and termios tests
ptsname(3) returns a pointer to a global variable, so it isn't
thread-safe. Protect it with a mutex.
Diffstat (limited to 'test/sys/test_termios.rs')
-rw-r--r-- | test/sys/test_termios.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/test/sys/test_termios.rs b/test/sys/test_termios.rs index c6572052..2455a4e5 100644 --- a/test/sys/test_termios.rs +++ b/test/sys/test_termios.rs @@ -18,10 +18,14 @@ fn write_all(f: RawFd, buf: &[u8]) { // Test tcgetattr on a terminal #[test] fn test_tcgetattr_pty() { - let pty = openpty(None, None).unwrap(); + // openpty uses ptname(3) internally + #[allow(unused_variables)] + let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + + let pty = openpty(None, None).expect("openpty failed"); assert!(termios::tcgetattr(pty.master).is_ok()); - close(pty.master).unwrap(); - close(pty.slave).unwrap(); + close(pty.master).expect("closing the master failed"); + close(pty.slave).expect("closing the slave failed"); } // Test tcgetattr on something that isn't a terminal #[test] @@ -41,12 +45,16 @@ fn test_tcgetattr_ebadf() { // Test modifying output flags #[test] fn test_output_flags() { + // openpty uses ptname(3) internally + #[allow(unused_variables)] + let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + // Open one pty to get attributes for the second one let mut termios = { - let pty = openpty(None, None).unwrap(); + let pty = openpty(None, None).expect("openpty failed"); assert!(pty.master > 0); assert!(pty.slave > 0); - let termios = tcgetattr(pty.master).unwrap(); + let termios = tcgetattr(pty.master).expect("tcgetattr failed"); close(pty.master).unwrap(); close(pty.slave).unwrap(); termios @@ -80,6 +88,10 @@ fn test_output_flags() { // Test modifying local flags #[test] fn test_local_flags() { + // openpty uses ptname(3) internally + #[allow(unused_variables)] + let m = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test"); + // Open one pty to get attributes for the second one let mut termios = { let pty = openpty(None, None).unwrap(); |