From 4aae81faf8c215351ec0f69714f67e36f8e154c7 Mon Sep 17 00:00:00 2001 From: Shunsuke Mie Date: Wed, 16 Nov 2022 00:22:38 +0900 Subject: [PATCH] fix(pty): use /bin/sh when SHELL env variable is not found (#1769) This commit fixes #1722. In some environment, the SHELL environemnt variable is not exists. It causes a panic that is reported as #1722. Use generic shell (/bin/sh) to prevent the panic. This is a same behavior as tmux. https://github.com/tmux/tmux/blob/master/spawn.c#L329-L331 --- zellij-server/src/pty.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs index ebf72e89..5034e7a6 100644 --- a/zellij-server/src/pty.rs +++ b/zellij-server/src/pty.rs @@ -433,9 +433,16 @@ impl Pty { } } pub fn get_default_terminal(&self, cwd: Option) -> TerminalAction { + let shell = PathBuf::from(env::var("SHELL").unwrap_or_else(|_| { + log::warn!("Cannot read SHELL env, falling back to use /bin/sh"); + "/bin/sh".to_string() + })); + if !shell.exists() { + panic!("Cannot find shell {}", shell.display()); + } TerminalAction::RunCommand(RunCommand { args: vec![], - command: PathBuf::from(env::var("SHELL").expect("Could not find the SHELL variable")), + command: shell, cwd, // note: this might also be filled by the calling function, eg. spawn_terminal hold_on_close: false, hold_on_start: false,