Skip to content

Commit

Permalink
flush
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Oct 25, 2024
1 parent 8e5b434 commit a915772
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::fs::File;
use std::io;
use std::io::Error;
use std::io::ErrorKind;
use std::io::Write;
Expand Down Expand Up @@ -78,19 +79,22 @@ fn poll_controller_fd_until_read(raw_fd: RawFd) {
if err == Errno::EINTR || err == Errno::EAGAIN {
// we were interrupted, so we should just try again
println!("poll interrupted");
io::stdout().flush().unwrap();
continue;
}

// we should almost never hit this, but if we do, we should just break out of the loop. this
// can happen if Node destroys the terminal before waiting for the child process to go away.
println!("poll error: {}", err);
io::stdout().flush().unwrap();
break;
}

// check if POLLIN is no longer set (i.e. there is no more data to read)
if let Some(flags) = poll_fd.revents() {
if !flags.contains(PollFlags::POLLIN) {
println!("poll complete");
io::stdout().flush().unwrap();
break;
}
}
Expand All @@ -102,6 +106,7 @@ fn poll_controller_fd_until_read(raw_fd: RawFd) {
} else {
// we have exhausted our attempts, its joever
println!("poll timeout");
io::stdout().flush().unwrap();
break;
}
}
Expand Down Expand Up @@ -169,6 +174,7 @@ impl Pty {
// right before we spawn the child, we should do a bunch of setup
// this is all run in the context of the child process
println!("pre_exec");
io::stdout().flush().unwrap();
cmd.pre_exec(move || {
// start a new session
let err = libc::setsid();
Expand Down Expand Up @@ -226,6 +232,7 @@ impl Pty {

// actually spawn the child
println!("spawn");
io::stdout().flush().unwrap();
let mut child = cmd.spawn()?;
let pid = child.id();

Expand All @@ -250,13 +257,17 @@ impl Pty {
drop(user_fd);

println!("start wait");
io::stdout().flush().unwrap();
let wait_result = child.wait();
println!("end wait");
io::stdout().flush().unwrap();

// try to wait for the controller fd to be fully read
println!("start poll");
io::stdout().flush().unwrap();
poll_controller_fd_until_read(raw_controller_fd);
println!("end poll");
io::stdout().flush().unwrap();

match wait_result {
Ok(status) => {
Expand Down

0 comments on commit a915772

Please sign in to comment.