diff options
author | Jesse Luehrs <doy@tozt.net> | 2021-12-31 06:13:29 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2021-12-31 06:13:29 -0500 |
commit | 42131f5f9ca126b0b9aeadd1510715bf525cb83f (patch) | |
tree | 1995b005d69e1fa327d662e57a30de9573617ab2 /src | |
parent | 85e3f0052b9ca5c084a93e8ae9e6cd6d5bc2ee5b (diff) | |
download | nbsh-42131f5f9ca126b0b9aeadd1510715bf525cb83f.tar.gz nbsh-42131f5f9ca126b0b9aeadd1510715bf525cb83f.zip |
setting the foreground process group needs to happen immediately
otherwise the first process might try to read from the tty and cause a
subsequently spawned process to stop in the middle of a spawn, which can
lead to deadlocks
Diffstat (limited to 'src')
-rw-r--r-- | src/pipe.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/pipe.rs b/src/pipe.rs index 3bba117..b75f937 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -1,7 +1,7 @@ use async_std::io::prelude::ReadExt as _; use async_std::os::unix::process::CommandExt as _; use async_std::stream::StreamExt as _; -use std::os::unix::io::{AsRawFd as _, FromRawFd as _}; +use std::os::unix::io::FromRawFd as _; use std::os::unix::process::ExitStatusExt as _; async fn read_pipeline() -> crate::parse::Pipeline { @@ -54,19 +54,24 @@ pub async fn run() { } if pg.is_none() { pg = Some(child.id().try_into().unwrap()); + let pty = nix::fcntl::open( + "/dev/tty", + nix::fcntl::OFlag::empty(), + nix::sys::stat::Mode::empty(), + ) + .unwrap(); + nix::unistd::tcsetpgrp( + pty, + nix::unistd::Pid::from_raw(pg.unwrap()), + ) + .unwrap(); + nix::unistd::close(pty).unwrap(); } futures.push(async move { (child.status_no_drop().await.unwrap(), i == last) }); } - let pty = std::fs::File::open("/dev/tty").unwrap(); - nix::unistd::tcsetpgrp( - pty.as_raw_fd(), - nix::unistd::Pid::from_raw(pg.unwrap()), - ) - .unwrap(); - let mut final_status = None; while let Some((status, last)) = futures.next().await { if status.signal() == Some(signal_hook::consts::signal::SIGINT) { |