Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double panic lockup in clients panic handler #1433

Merged
merged 5 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions zellij-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod input_handler;
mod stdin_ansi_parser;
mod stdin_handler;

use log::error;
use log::info;
use std::env::current_exe;
use std::io::{self, Write};
Expand Down Expand Up @@ -124,7 +125,7 @@ pub fn start_client(
let clear_client_terminal_attributes = "\u{1b}[?1l\u{1b}=\u{1b}[r\u{1b}12l\u{1b}[?1000l\u{1b}[?1002l\u{1b}[?1003l\u{1b}[?1005l\u{1b}[?1006l\u{1b}[?12l";
let take_snapshot = "\u{1b}[?1049h";
let bracketed_paste = "\u{1b}[?2004h";
os_input.unset_raw_mode(0);
os_input.unset_raw_mode(0).unwrap();

let _ = os_input
.get_stdout_writer()
Expand Down Expand Up @@ -201,8 +202,10 @@ pub fn start_client(
let send_client_instructions = send_client_instructions.clone();
let os_input = os_input.clone();
Box::new(move |info| {
os_input.unset_raw_mode(0);
handle_panic(info, &send_client_instructions);
error!("Panic occured in client:\n{:?}", info);
if let Ok(()) = os_input.unset_raw_mode(0) {
handle_panic(info, &send_client_instructions);
}
})
});

Expand Down Expand Up @@ -293,7 +296,7 @@ pub fn start_client(
.unwrap();

let handle_error = |backtrace: String| {
os_input.unset_raw_mode(0);
os_input.unset_raw_mode(0).unwrap();
let goto_start_of_last_line = format!("\u{1b}[{};{}H", full_screen_ws.rows, 1);
let restore_snapshot = "\u{1b}[?1049l";
os_input.disable_mouse();
Expand Down Expand Up @@ -364,7 +367,7 @@ pub fn start_client(

os_input.disable_mouse();
info!("{}", exit_msg);
os_input.unset_raw_mode(0);
os_input.unset_raw_mode(0).unwrap();
let mut stdout = os_input.get_stdout_writer();
let _ = stdout.write(goodbye_message.as_bytes()).unwrap();
stdout.flush().unwrap();
Expand Down
13 changes: 5 additions & 8 deletions zellij-client/src/os_input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ fn into_raw_mode(pid: RawFd) {
};
}

fn unset_raw_mode(pid: RawFd, orig_termios: termios::Termios) {
match termios::tcsetattr(pid, termios::SetArg::TCSANOW, &orig_termios) {
Ok(_) => {}
Err(e) => panic!("error {:?}", e),
};
fn unset_raw_mode(pid: RawFd, orig_termios: termios::Termios) -> Result<(), nix::Error> {
termios::tcsetattr(pid, termios::SetArg::TCSANOW, &orig_termios)
}

pub(crate) fn get_terminal_size_using_fd(fd: RawFd) -> Size {
Expand Down Expand Up @@ -81,7 +78,7 @@ pub trait ClientOsApi: Send + Sync {
fn set_raw_mode(&mut self, fd: RawFd);
/// Set the terminal associated to file descriptor `fd` to
/// [cooked mode](https://en.wikipedia.org/wiki/Terminal_mode).
fn unset_raw_mode(&self, fd: RawFd);
fn unset_raw_mode(&self, fd: RawFd) -> Result<(), nix::Error>;
/// Returns the writer that allows writing to standard output.
fn get_stdout_writer(&self) -> Box<dyn io::Write>;
fn get_stdin_reader(&self) -> Box<dyn io::Read>;
Expand Down Expand Up @@ -111,9 +108,9 @@ impl ClientOsApi for ClientOsInputOutput {
fn set_raw_mode(&mut self, fd: RawFd) {
into_raw_mode(fd);
}
fn unset_raw_mode(&self, fd: RawFd) {
fn unset_raw_mode(&self, fd: RawFd) -> Result<(), nix::Error> {
let orig_termios = self.orig_termios.lock().unwrap();
unset_raw_mode(fd, orig_termios.clone());
unset_raw_mode(fd, orig_termios.clone())
}
fn box_clone(&self) -> Box<dyn ClientOsApi> {
Box::new((*self).clone())
Expand Down
3 changes: 2 additions & 1 deletion zellij-client/src/unit/input_handler_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use zellij_utils::nix;
use super::input_loop;
use zellij_utils::input::actions::{Action, Direction};
use zellij_utils::input::config::Config;
Expand Down Expand Up @@ -125,7 +126,7 @@ impl ClientOsApi for FakeClientOsApi {
fn set_raw_mode(&mut self, _fd: RawFd) {
unimplemented!()
}
fn unset_raw_mode(&self, _fd: RawFd) {
fn unset_raw_mode(&self, _fd: RawFd) -> Result<(), nix::Error> {
unimplemented!()
}
fn get_stdout_writer(&self) -> Box<dyn io::Write> {
Expand Down