diff options
| author | Thomas Linford <tlinford@users.noreply.github.com> | 2021-05-16 18:00:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-16 17:00:22 +0100 |
| commit | 28212f54309d09263c6daa1801d49e8b4311be12 (patch) | |
| tree | 7465e20ae3a48fb3399cf8d8fd0a07b89f00a9ba /src | |
| parent | Docs(changelog): Multiprocess model #499 (diff) | |
| download | sl0ppij-28212f54309d09263c6daa1801d49e8b4311be12.tar.gz sl0ppij-28212f54309d09263c6daa1801d49e8b4311be12.tar.xz sl0ppij-28212f54309d09263c6daa1801d49e8b4311be12.zip | |
handle error on termios initialization (#511)
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/os_input_output.rs | 16 | ||||
| -rw-r--r-- | 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<dyn ServerOsApi> { } } -pub fn get_server_os_input() -> ServerOsInputOutput { - let current_termios = termios::tcgetattr(0).unwrap(); +pub fn get_server_os_input() -> Result<ServerOsInputOutput, nix::Error> { + 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<dyn ClientOsApi> { } } -pub fn get_client_os_input() -> ClientOsInputOutput { - let current_termios = termios::tcgetattr(0).unwrap(); +pub fn get_client_os_input() -> Result<ClientOsInputOutput, nix::Error> { + 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); } } |
