diff --git a/teletypewriter/examples/spawn.rs b/teletypewriter/examples/spawn.rs index 60ab16f9..93673a8d 100644 --- a/teletypewriter/examples/spawn.rs +++ b/teletypewriter/examples/spawn.rs @@ -10,7 +10,7 @@ fn main() -> std::io::Result<()> { use teletypewriter::{create_pty_with_fork, ProcessReadWrite, Pty}; let shell = Cow::Borrowed("bash"); - let mut process: Pty = create_pty_with_fork(&shell, 80, 25); + let mut process: Pty = create_pty_with_fork(&shell, 80, 25)?; process.writer().write_all(b"1").unwrap(); process.writer().write_all(b"2").unwrap(); diff --git a/teletypewriter/src/unix/mod.rs b/teletypewriter/src/unix/mod.rs index c6c87e98..ed08fc12 100644 --- a/teletypewriter/src/unix/mod.rs +++ b/teletypewriter/src/unix/mod.rs @@ -509,9 +509,7 @@ pub fn create_pty_with_spawn( } if is_controling_terminal { - if let Err(err_message) = set_controlling_terminal(child) { - return Err(err_message); - } + set_controlling_terminal(child)?; } // No longer need child/main fds. @@ -617,10 +615,10 @@ pub fn create_pty_with_fork(shell: &str, columns: u16, rows: u16) -> Result { default_shell_command(shell_program); - return Err(Error::new( + Err(Error::new( ErrorKind::Other, format!("forkpty has reach unreachable with {}", shell_program), - )); + )) } id if id > 0 => { // TODO: Currently we fork the process and don't wait to know if led to failure @@ -648,12 +646,10 @@ pub fn create_pty_with_fork(shell: &str, columns: u16, rows: u16) -> Result { - return Err(Error::new( - ErrorKind::Other, - format!("forkpty failed using {}", shell_program), - )); - } + _ => Err(Error::new( + ErrorKind::Other, + format!("forkpty failed using {}", shell_program), + )), } } @@ -672,7 +668,7 @@ fn set_controlling_terminal(fd: libc::c_int) -> Result<(), Error> { return Err(Error::last_os_error()); } - return Ok(()); + Ok(()) } // https://man7.org/linux/man-pages/man2/fcntl.2.html