Skip to content

Commit

Permalink
even more print debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Oct 25, 2024
1 parent f5cfe8b commit 79567f6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,20 @@ fn poll_controller_fd_until_read(raw_fd: RawFd) {
if let Err(err) = poll(&mut [poll_fd], PollTimeout::ZERO) {
if err == Errno::EINTR || err == Errno::EAGAIN {
// we were interrupted, so we should just try again
println!("poll interrupted");
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);
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");
break;
}
}
Expand All @@ -98,6 +101,7 @@ fn poll_controller_fd_until_read(raw_fd: RawFd) {
continue;
} else {
// we have exhausted our attempts, its joever
println!("poll timeout");
break;
}
}
Expand Down Expand Up @@ -164,6 +168,7 @@ impl Pty {
unsafe {
// 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");
cmd.pre_exec(move || {
// start a new session
let err = libc::setsid();
Expand Down Expand Up @@ -220,6 +225,7 @@ impl Pty {
}

// actually spawn the child
println!("spawn");
let mut child = cmd.spawn()?;
let pid = child.id();

Expand All @@ -243,10 +249,14 @@ impl Pty {
thread::spawn(move || {
drop(user_fd);

println!("start wait");
let wait_result = child.wait();
println!("end wait");

// try to wait for the controller fd to be fully read
println!("start poll");
poll_controller_fd_until_read(raw_controller_fd);
println!("end poll");

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

0 comments on commit 79567f6

Please sign in to comment.