Skip to content

Commit

Permalink
forkpty: Fix test on BSDs
Browse files Browse the repository at this point in the history
  • Loading branch information
kkuehlz committed Apr 10, 2019
1 parent e0f1a90 commit 648b81d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions test/test_pty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ use std::path::Path;
use std::os::unix::prelude::*;
use tempfile::tempfile;

use libc::_exit;
use nix::fcntl::{OFlag, open};
use nix::pty::*;
use nix::sys::stat;
use nix::sys::termios::*;
use nix::sys::wait::wait;
use nix::unistd::{write, close};
use nix::unistd::{write, close, pause};

/// Regression test for Issue #659
/// This is the correct way to explicitly close a `PtyMaster`
Expand Down Expand Up @@ -207,6 +205,8 @@ fn test_openpty_with_termios() {
#[test]
fn test_forkpty() {
use nix::unistd::ForkResult::*;
use nix::sys::signal::*;
use nix::sys::wait::wait;
// forkpty calls openpty which uses ptname(3) internally.
let _m0 = ::PTSNAME_MTX.lock().expect("Mutex got poisoned by another test");
// forkpty spawns a child process
Expand All @@ -218,13 +218,14 @@ fn test_forkpty() {
match pty.fork_result {
Child => {
write(0, string.as_bytes()).unwrap();
unsafe { _exit(0) }
pause(); // we need the child to stay alive until the parent calls read
},
Parent { child } => {
wait().unwrap(); // keep other tests using generic wait from getting our child
let mut buf = [0u8; 10];
assert!(child.as_raw() > 0);
::read_exact(pty.master, &mut buf);
kill(child, SIGTERM).unwrap();
wait().unwrap(); // keep other tests using generic wait from getting our child
assert_eq!(&buf, echoed_string.as_bytes());
close(pty.master).unwrap();
},
Expand Down

0 comments on commit 648b81d

Please sign in to comment.