From 3b9be25161ed88e9b694c21a21ffbb4aaade3d52 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 15 Jun 2022 10:37:57 -0700 Subject: [PATCH] avoid spawn failures after using `sudo -i` The heart of the issue is that `sudo -i` sets the cwd to the homedir of the root user, and that isn't accessible to the regular unprivileged user, and cannot be set as the cwd for the newly spawned panes/tabs. A secondary issue is that it is hard to see what the error is without improved diagnostics. So this improves the diagnostics, and then changes the existence check that we were doing for local domain spawns to try to read the directory instead. refs: https://github.com/wez/wezterm/issues/2120 --- docs/changelog.md | 1 + mux/src/domain.rs | 10 +++++++++- mux/src/lib.rs | 10 +++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 45532859d..0bdb8fce2 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -83,6 +83,7 @@ As features stabilize some brief notes about them will accumulate here. * Synthesized bold didn't kick in for automatically computed `font_rules`. [#2074](https://github.com/wez/wezterm/issues/2074) * Added [freetype_pcf_long_family_names](config/lua/config/freetype_pcf_long_family_names.md) option to workaround PCF font naming issues on certain Linux distributions. [#2100](https://github.com/wez/wezterm/issues/2100) * X11/Wayland: wezterm.desktop now specifies `StartupWMClass`. Thanks to [@uncomfyhalomacro](https://github.com/uncomfyhalomacro)! [#2052](https://github.com/wez/wezterm/issues/2052) [#2125](https://github.com/wez/wezterm/pull/2125) +* `sudo -i` in a pane would cause subsequent pane/tab creation to fail until the cwd was changed to an accessible directory [#2120](https://github.com/wez/wezterm/issues/2120) ### 20220408-101518-b908e2dd diff --git a/mux/src/domain.rs b/mux/src/domain.rs index 2a0fdeab2..1ff2e3979 100644 --- a/mux/src/domain.rs +++ b/mux/src/domain.rs @@ -254,7 +254,15 @@ impl LocalDomain { // can be painful; in the case where a tab is local but has connected // to a remote system and that remote has used OSC 7 to set a path // that doesn't exist on the local system, process spawning can fail. - if !std::path::Path::new(&dir).exists() { + // Another situation is `sudo -i` has the pane with set to a cwd + // that is not accessible to the user. + if let Err(err) = std::path::Path::new(&dir).read_dir() { + log::warn!( + "Directory {:?} is not readable and will not be \ + used for the command we are spawning: {:#}", + dir, + err + ); cmd.clear_cwd(); } } diff --git a/mux/src/lib.rs b/mux/src/lib.rs index fcade7ff8..1e433eda0 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -1100,7 +1100,15 @@ impl Mux { }, ); - let tab = domain.spawn(size, command, cwd, window_id).await?; + let tab = domain + .spawn(size, command.clone(), cwd.clone(), window_id) + .await + .with_context(|| { + format!( + "Spawning in domain `{}`: {size:?} command={command:?} cwd={cwd:?}", + domain.domain_name() + ) + })?; let pane = tab .get_active_pane()