F1: lutra starts the desktop without passing on any handle

lutra_proc::spawn_detached starts a program through CreateProcessW with
bInheritHandles = FALSE and null standard handles (DETACHED_PROCESS |
CREATE_NEW_PROCESS_GROUP as before), so lutra's output pipe closes when
lutra exits. launch.rs uses it. Helper roles detached-plain/-proc show the
standard library keeping the pipe open and spawn_detached not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-11-02 19:04:54 +01:00
parent 8a05f508c8
commit f4dbc9188e
7 changed files with 340 additions and 33 deletions

View file

@ -135,3 +135,48 @@ fn dropping_an_adopt_guard_takes_the_tree_started_after_it() {
assert_gone(reader);
parent.wait().unwrap();
}
/// Starts the helper in a `detached-*` role, reads the grandchild's id and
/// returns it with whether the output then reached end of file within
/// `within`. Kills the grandchild before returning.
fn detached_output_closes(role: &str, within: Duration) -> bool {
let mut parent = helper(role).spawn().unwrap();
let mut reader = BufReader::new(parent.stdout.take().unwrap());
let mut line = String::new();
reader.read_line(&mut line).unwrap();
let id: u32 = line.trim().parse().unwrap();
assert!(parent.wait().unwrap().success());
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let mut rest = Vec::new();
let _ = reader.read_to_end(&mut rest);
let _ = tx.send(());
});
let closed = rx.recv_timeout(within).is_ok();
let kill = if cfg!(windows) {
Command::new("taskkill")
.args(["/F", "/PID", &id.to_string()])
.output()
} else {
Command::new("kill").args(["-9", &id.to_string()]).output()
};
kill.unwrap();
closed
}
#[test]
fn a_detached_start_holds_none_of_the_callers_handles() {
assert!(
detached_output_closes("detached-proc", GONE_WITHIN),
"the detached grandchild holds its parent's output pipe"
);
}
#[cfg(windows)]
#[test]
fn a_plain_detached_start_inherits_the_callers_pipe_on_windows() {
assert!(
!detached_output_closes("detached-plain", Duration::from_secs(3)),
"the standard library no longer passes inheritable handles on; spawn_detached may be simpler now"
);
}