Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions apps/staged/src-tauri/src/shell_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,21 @@ async fn capture_shell_env(
.stderr(Stdio::null())
.kill_on_drop(true);

// Detach from the parent's controlling TTY so an interactive `$SHELL -ils`
// can't `tcsetpgrp` onto the user's terminal or mutate its modes via
// rcfiles. Without this, the spawned shell inherits the staged binary's
// ctty (the user's real /dev/tty up the chain), and on exit leaves the
// user's TTY foreground-PG pointing at a dead PGID — the outer zsh later
// dies with EIO on read.
#[cfg(unix)]
unsafe {
// SAFETY: `setsid()` is async-signal-safe.
cmd.pre_exec(|| {
libc::setsid();
Ok(())
});
}

let mut child = cmd.spawn()?;
{
let mut stdin = child
Expand Down Expand Up @@ -534,6 +549,17 @@ fn capture_shell_env_blocking(
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null());

// See `capture_shell_env` for why this is required.
#[cfg(unix)]
unsafe {
use std::os::unix::process::CommandExt;
// SAFETY: `setsid()` is async-signal-safe.
cmd.pre_exec(|| {
libc::setsid();
Ok(())
});
}

let mut child = cmd.spawn()?;
{
let mut stdin = child
Expand Down