From 86842837c15621760bf0d4372f8f207e571d3119 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 25 Feb 2022 21:29:19 -0500 Subject: hold the pts open while the pty task is running to avoid EIO errors --- src/shell/history/pty.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/shell/history/pty.rs b/src/shell/history/pty.rs index 8825f12..58f872c 100644 --- a/src/shell/history/pty.rs +++ b/src/shell/history/pty.rs @@ -1,7 +1,7 @@ use crate::shell::prelude::*; pub struct Pty { - pts: pty_process::Pts, + pts: std::sync::Arc, close_w: tokio::sync::mpsc::UnboundedSender<()>, } @@ -17,10 +17,11 @@ impl Pty { let pty = pty_process::Pty::new()?; pty.resize(pty_process::Size::new(size.0, size.1))?; - let pts = pty.pts()?; + let pts = std::sync::Arc::new(pty.pts()?); tokio::task::spawn(pty_task( pty, + std::sync::Arc::clone(&pts), crate::mutex::clone(entry), input_r, resize_r, @@ -35,7 +36,7 @@ impl Pty { &self, mut cmd: pty_process::Command, ) -> anyhow::Result { - Ok(cmd.spawn(&self.pts)?) + Ok(cmd.spawn(&*self.pts)?) } pub async fn close(&self) { @@ -45,6 +46,9 @@ impl Pty { async fn pty_task( pty: pty_process::Pty, + // take the pts here just to ensure that we don't close it before this + // task finishes, otherwise the read call can return EIO + _pts: std::sync::Arc, entry: crate::mutex::Mutex, input_r: tokio::sync::mpsc::UnboundedReceiver>, resize_r: tokio::sync::mpsc::UnboundedReceiver<(u16, u16)>, -- cgit v1.2.3-54-g00ecf