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
This commit is contained in:
Shunsuke Mie 2022-11-16 00:22:38 +09:00 committed by GitHub
parent c66a8c0629
commit 4aae81faf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -433,9 +433,16 @@ impl Pty {
} }
} }
pub fn get_default_terminal(&self, cwd: Option<PathBuf>) -> TerminalAction { pub fn get_default_terminal(&self, cwd: Option<PathBuf>) -> 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 { TerminalAction::RunCommand(RunCommand {
args: vec![], 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 cwd, // note: this might also be filled by the calling function, eg. spawn_terminal
hold_on_close: false, hold_on_close: false,
hold_on_start: false, hold_on_start: false,