Detach Unix hook commands from the controlling terminal (#43876)

## Why

Shell startup code that accesses the controlling terminal can stop a hook on background terminal I/O, preventing the hook command from running.

## What changed

Use `detach_from_tty` before executing Unix hook commands to avoid inheriting the controlling terminal while preserving process-group cleanup.

## Testing

Add a Unix regression test that runs under a controlling terminal and uses `BASH_ENV` to invoke `stty` during shell startup. Verify that the hook completes successfully and produces the expected output.

GitOrigin-RevId: 231125d4b169fb1bd828e3f8e96476a13bd25d26
This commit is contained in:
Abhinav
2026-09-08 18:04:48 +00:00
committed by copyberry
parent c1f1467f30
commit cfd5d77d63
2 changed files with 116 additions and 1 deletions
+6 -1
View File
@@ -222,7 +222,12 @@ pub(crate) async fn run_command(
.kill_on_drop(true);
#[cfg(unix)]
command.process_group(0);
// Keep process-group cleanup without inheriting the controlling terminal, where
// shell startup can otherwise stop the hook on background terminal I/O.
// SAFETY: detach_from_tty only performs async-signal-safe process setup.
unsafe {
command.pre_exec(codex_utils_pty::process_group::detach_from_tty);
}
#[cfg(windows)]
let mut process_tree_job = JobObject::create().ok();