fix(platform): in the Flatpak a pass's shell is bash

Flatpak sets SHELL to /bin/sh, the host's (zsh here) being no file of
the Sdk's, and claude's Bash tool runs commands with bash or zsh. In the
sandbox SHELL becomes /bin/bash unless it names a bash or zsh that is
there. Found by the sandbox checks: a pass's environment had SHELL=/bin/sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-10-31 16:09:40 +01:00
commit aaa0bb1059
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
3 changed files with 30 additions and 1 deletions

View file

@ -205,6 +205,21 @@ int main() {
Check(Platform::GetEnv("XDG_CONFIG_HOME") == "/elsewhere/config", "a host XDG directory the host set comes back");
Check(Platform::GetEnv("XDG_CACHE_HOME") == Dyn::JoinPath(home, ".cache"), "one it left unset is the XDG default under $HOME");
Check(Platform::GetEnv("XDG_STATE_HOME") == Dyn::JoinPath(home, ".local/state"), "state too");
// The shell: the sandbox's /bin/sh becomes bash; a bash or zsh that is
// there stays.
const std::optional<std::string> shell = Platform::GetEnv("SHELL");
setenv("SHELL", "/bin/sh", 1);
Platform::RestoreShell();
const std::optional<std::string> fromSh = Platform::GetEnv("SHELL");
setenv("SHELL", "/no/such/zsh", 1);
Platform::RestoreShell();
const std::optional<std::string> fromMissing = Platform::GetEnv("SHELL");
setenv("SHELL", "/bin/bash", 1);
Platform::RestoreShell();
const std::optional<std::string> fromBash = Platform::GetEnv("SHELL");
if (shell) setenv("SHELL", shell->c_str(), 1);
Check(!fs::exists("/bin/bash") || (fromSh == "/bin/bash" && fromMissing == "/bin/bash" && fromBash == "/bin/bash"),
"SHELL: /bin/sh and a shell that is not there become /bin/bash; bash stays");
}
{