1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 05:12:40 +03:00

pty: set SHELL to the shell we selected

refs: #2469
This commit is contained in:
Wez Furlong 2022-09-01 05:37:51 -07:00
parent 9082c79b34
commit c0a841eecb
2 changed files with 24 additions and 18 deletions

View File

@ -488,7 +488,7 @@ impl Domain for LocalDomain {
let command_description = format!( let command_description = format!(
"\"{}\" in domain \"{}\"", "\"{}\" in domain \"{}\"",
if command_line.is_empty() { if command_line.is_empty() {
cmd.get_shell()? cmd.get_shell()
} else { } else {
command_line command_line
}, },

View File

@ -412,10 +412,9 @@ impl CommandBuilder {
.map(|dir| dir.as_os_str()) .map(|dir| dir.as_os_str())
.filter(|dir| std::path::Path::new(dir).is_dir()) .filter(|dir| std::path::Path::new(dir).is_dir())
.unwrap_or(home.as_ref()); .unwrap_or(home.as_ref());
let shell = self.get_shell();
let mut cmd = if self.is_default_prog() { let mut cmd = if self.is_default_prog() {
let shell = self.get_shell()?;
let mut cmd = std::process::Command::new(&shell); let mut cmd = std::process::Command::new(&shell);
// Run the shell as a login shell by prefixing the shell's // Run the shell as a login shell by prefixing the shell's
@ -434,6 +433,7 @@ impl CommandBuilder {
cmd.current_dir(dir); cmd.current_dir(dir);
cmd.env_clear(); cmd.env_clear();
cmd.env("SHELL", shell);
cmd.envs(self.envs.values().map( cmd.envs(self.envs.values().map(
|EnvEntry { |EnvEntry {
is_from_base_env: _, is_from_base_env: _,
@ -448,7 +448,7 @@ impl CommandBuilder {
/// Determine which shell to run. /// Determine which shell to run.
/// We take the contents of the $SHELL env var first, then /// We take the contents of the $SHELL env var first, then
/// fall back to looking it up from the password database. /// fall back to looking it up from the password database.
pub fn get_shell(&self) -> anyhow::Result<String> { pub fn get_shell(&self) -> String {
use nix::unistd::{access, AccessFlags}; use nix::unistd::{access, AccessFlags};
use std::ffi::CStr; use std::ffi::CStr;
use std::path::Path; use std::path::Path;
@ -456,7 +456,7 @@ impl CommandBuilder {
if let Some(shell) = self.get_env("SHELL").and_then(OsStr::to_str) { if let Some(shell) = self.get_env("SHELL").and_then(OsStr::to_str) {
match access(shell, AccessFlags::X_OK) { match access(shell, AccessFlags::X_OK) {
Ok(()) => return Ok(shell.into()), Ok(()) => return shell.into(),
Err(err) => log::warn!( Err(err) => log::warn!(
"$SHELL -> {shell:?} which is \ "$SHELL -> {shell:?} which is \
not executable ({err:#}), falling back to password db lookup" not executable ({err:#}), falling back to password db lookup"
@ -467,21 +467,27 @@ impl CommandBuilder {
let ent = unsafe { libc::getpwuid(libc::getuid()) }; let ent = unsafe { libc::getpwuid(libc::getuid()) };
if !ent.is_null() { if !ent.is_null() {
let shell = unsafe { CStr::from_ptr((*ent).pw_shell) }; let shell = unsafe { CStr::from_ptr((*ent).pw_shell) };
let shell = shell match shell.to_str().map(str::to_owned) {
.to_str() Err(err) => {
.map(str::to_owned) log::warn!(
.context("failed to resolve shell from passwd database")?; "passwd database shell could not be \
represented as utf-8: {err:#}, \
if let Err(err) = access(Path::new(&shell), AccessFlags::X_OK) { falling back to /bin/sh"
log::warn!( );
"passwd database shell={shell:?} which is \ }
not executable ({err:#}), fallback to /bin/sh" Ok(shell) => {
); if let Err(err) = access(Path::new(&shell), AccessFlags::X_OK) {
} else { log::warn!(
return Ok(shell) "passwd database shell={shell:?} which is \
not executable ({err:#}), falling back to /bin/sh"
);
} else {
return shell;
}
}
} }
} }
Ok("/bin/sh".into()) "/bin/sh".into()
} }
fn get_home_dir(&self) -> anyhow::Result<String> { fn get_home_dir(&self) -> anyhow::Result<String> {