From 28212f54309d09263c6daa1801d49e8b4311be12 Mon Sep 17 00:00:00 2001 From: Thomas Linford Date: Sun, 16 May 2021 18:00:22 +0200 Subject: [PATCH] handle error on termios initialization (#511) --- src/common/os_input_output.rs | 16 ++++++++-------- src/main.rs | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs index adde6fdf..6b849efa 100644 --- a/src/common/os_input_output.rs +++ b/src/common/os_input_output.rs @@ -275,14 +275,14 @@ impl Clone for Box { } } -pub fn get_server_os_input() -> ServerOsInputOutput { - let current_termios = termios::tcgetattr(0).unwrap(); +pub fn get_server_os_input() -> Result { + let current_termios = termios::tcgetattr(0)?; let orig_termios = Arc::new(Mutex::new(current_termios)); - ServerOsInputOutput { + Ok(ServerOsInputOutput { orig_termios, receive_instructions_from_client: None, send_instructions_to_client: Arc::new(Mutex::new(None)), - } + }) } #[derive(Clone)] @@ -403,12 +403,12 @@ impl Clone for Box { } } -pub fn get_client_os_input() -> ClientOsInputOutput { - let current_termios = termios::tcgetattr(0).unwrap(); +pub fn get_client_os_input() -> Result { + let current_termios = termios::tcgetattr(0)?; let orig_termios = Arc::new(Mutex::new(current_termios)); - ClientOsInputOutput { + Ok(ClientOsInputOutput { orig_termios, send_instructions_to_server: Arc::new(Mutex::new(None)), receive_instructions_from_server: Arc::new(Mutex::new(None)), - } + }) } diff --git a/src/main.rs b/src/main.rs index 49e42ffb..12842b58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,10 +39,22 @@ pub fn main() { atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap(); atomic_create_dir(&*ZELLIJ_TMP_LOG_DIR).unwrap(); if let Some(path) = opts.server { - let os_input = get_server_os_input(); + let os_input = match get_server_os_input() { + Ok(server_os_input) => server_os_input, + Err(e) => { + eprintln!("failed to open terminal:\n{}", e); + std::process::exit(1); + } + }; start_server(Box::new(os_input), path); } else { - let os_input = get_client_os_input(); + let os_input = match get_client_os_input() { + Ok(os_input) => os_input, + Err(e) => { + eprintln!("failed to open terminal:\n{}", e); + std::process::exit(1); + } + }; start_client(Box::new(os_input), opts, config); } }