feat: detach non-tty childs (#9477)

Thanks to the investigations made by
* @frantic-openai https://github.com/openai/codex/pull/9403
* @kfiramar https://github.com/openai/codex/pull/9388
This commit is contained in:
jif-oai
2026-01-19 11:35:34 +00:00
committed by GitHub
parent 186794dbb3
commit dc1b62acbd
5 changed files with 76 additions and 4 deletions
+7
View File
@@ -135,6 +135,13 @@ async fn run_shell_script_with_timeout(
// returns a ref of handler.
let mut handler = Command::new(&args[0]);
handler.args(&args[1..]);
#[cfg(unix)]
unsafe {
handler.pre_exec(|| {
codex_utils_pty::process_group::detach_from_tty()?;
Ok(())
});
}
handler.kill_on_drop(true);
let output = timeout(snapshot_timeout, handler.output())
.await
+3 -3
View File
@@ -66,12 +66,12 @@ pub(crate) async fn spawn_child_async(
#[cfg(unix)]
unsafe {
let set_process_group = matches!(stdio_policy, StdioPolicy::RedirectForShellTool);
let detach_from_tty = matches!(stdio_policy, StdioPolicy::RedirectForShellTool);
#[cfg(target_os = "linux")]
let parent_pid = libc::getpid();
cmd.pre_exec(move || {
if set_process_group {
codex_utils_pty::process_group::set_process_group()?;
if detach_from_tty {
codex_utils_pty::process_group::detach_from_tty()?;
}
// This relies on prctl(2), so it only works on Linux.