Skip to content
Closed
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
18 changes: 18 additions & 0 deletions codex-rs/core/src/shell_snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::io::ErrorKind;
use std::path::Path;
use std::path::PathBuf;
use std::process::Stdio;
use std::time::Duration;
use std::time::SystemTime;

Expand Down Expand Up @@ -136,6 +137,20 @@ async fn run_shell_script_with_timeout(
let mut handler = Command::new(&args[0]);
handler.args(&args[1..]);
handler.kill_on_drop(true);
// Avoid inheriting the interactive TTY. This prevents snapshot shells or RCs from
// altering the terminal state while the TUI is in raw mode.
handler.stdin(Stdio::null());
handler.env("CODEX_SHELL_SNAPSHOT", "1");
Comment thread
kfiramar marked this conversation as resolved.
#[cfg(unix)]
{
// Detach from the controlling terminal to avoid tty side effects.
unsafe {
handler.pre_exec(|| {
let _ = libc::setsid();
Ok(())
});
}
}
let output = timeout(snapshot_timeout, handler.output())
.await
.map_err(|_| anyhow!("Snapshot command timed out for {shell_name}"))?
Expand All @@ -157,6 +172,7 @@ else
rc="$HOME/.zshrc"
fi
[[ -r "$rc" ]] && . "$rc"
unset CODEX_SHELL_SNAPSHOT
print '# Snapshot file'
print '# Unset all aliases to avoid conflicts with functions'
print 'unalias -a 2>/dev/null || true'
Expand All @@ -181,6 +197,7 @@ fn bash_snapshot_script() -> &'static str {
r##"if [ -z "$BASH_ENV" ] && [ -r "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
unset CODEX_SHELL_SNAPSHOT
echo '# Snapshot file'
echo '# Unset all aliases to avoid conflicts with functions'
unalias -a 2>/dev/null || true
Expand Down Expand Up @@ -208,6 +225,7 @@ fn sh_snapshot_script() -> &'static str {
r##"if [ -n "$ENV" ] && [ -r "$ENV" ]; then
. "$ENV"
fi
unset CODEX_SHELL_SNAPSHOT
echo '# Snapshot file'
echo '# Unset all aliases to avoid conflicts with functions'
unalias -a 2>/dev/null || true
Expand Down
Loading