Preserve Session Terminal TTY through causal launch

This commit is contained in:
ms2k 2026-07-17 16:54:42 +09:00
commit 39307f4281
2 changed files with 87 additions and 8 deletions

View file

@ -1376,7 +1376,12 @@ pub fn parse_wrapper_arguments(
if arguments.next().as_deref() != Some(OsStr::new("--")) {
return Err(io::Error::other("wrapper target separator is missing"));
}
Some(File::open(format!("/proc/self/fd/{descriptor}"))?)
Some(
File::options()
.read(true)
.write(true)
.open(format!("/proc/self/fd/{descriptor}"))?,
)
} else if next.as_deref() == Some(OsStr::new("--")) {
None
} else {

View file

@ -88,7 +88,9 @@ fn terminal_child_restores_slave_stdin_and_merges_output() -> std::io::Result<()
let slave = File::from(slave);
let target = TargetCommand::new("/bin/sh")
.argument("-c")
.argument("read value; printf 'out:%s\\n' \"$value\"; printf 'err\\n' >&2")
.argument(
"read value; printf 'stdin-fd\\n' >&0; printf 'out:%s\\n' \"$value\"; printf 'err\\n' >&2",
)
.with_target_stdin(slave.try_clone()?)?;
let expected_parent = current_process_identity()?;
let ownership = ProcessOwnershipContext {
@ -117,10 +119,13 @@ fn terminal_child_restores_slave_stdin_and_merges_output() -> std::io::Result<()
let _ = read_available(&mut master, &mut merged);
let exit = child_broker().reap_status(process)?;
let text = String::from_utf8_lossy(&merged);
let stdin = text.find("stdin-fd");
let out = text.find("out:hello");
let err = text.find("err");
if !matches!((out, err), (Some(out), Some(err)) if out < err)
|| exit.exit_code != Some(0)
if !matches!(
(stdin, out, err),
(Some(stdin), Some(out), Some(err)) if stdin < out && out < err
) || exit.exit_code != Some(0)
|| exit.terminating_signal.is_some()
{
return Err(std::io::Error::other(format!(