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:
parent
8a05f508c8
commit
f4dbc9188e
7 changed files with 340 additions and 33 deletions
|
|
@ -18,6 +18,7 @@ path = "src/main.rs"
|
|||
[dependencies]
|
||||
lutra-control.workspace = true
|
||||
lutra-mcp.workspace = true
|
||||
lutra-proc.workspace = true
|
||||
serde_json = "1.0.154"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
//! Finding and starting the desktop app when no Lutra is running.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
|
|
@ -70,11 +69,13 @@ fn resolve_link(path: PathBuf) -> PathBuf {
|
|||
std::fs::canonicalize(&path).unwrap_or(path)
|
||||
}
|
||||
|
||||
/// Starts `desktop` detached from this terminal (Windows: a detached process
|
||||
/// in a new process group; Unix: a new process group, so a Ctrl-C or
|
||||
/// hangup aimed at the terminal's foreground group does not reach it) and
|
||||
/// waits until it answers
|
||||
/// on the rendezvous file in `dir`. A desktop that exits successfully may
|
||||
/// Starts `desktop` detached from this terminal through
|
||||
/// [`lutra_proc::spawn_detached`] (Windows: a detached process in a new
|
||||
/// process group that inherits none of this process's handles, so a script
|
||||
/// reading `lutra`'s output through a pipe gets end of file as soon as
|
||||
/// `lutra` exits; Unix: a new process group, so a Ctrl-C or hangup aimed at
|
||||
/// the terminal's foreground group does not reach it) and waits until it
|
||||
/// answers on the rendezvous file in `dir`. A desktop that exits successfully may
|
||||
/// have forwarded to an instance that started at the same time, so only a
|
||||
/// failed exit ends the wait early.
|
||||
///
|
||||
|
|
@ -82,25 +83,7 @@ fn resolve_link(path: PathBuf) -> PathBuf {
|
|||
/// A message if it cannot be started, exits early, or does not answer
|
||||
/// within [`START_TIMEOUT`].
|
||||
pub fn start(desktop: &Path, dir: &Path) -> Result<Client, String> {
|
||||
let mut command = Command::new(desktop);
|
||||
command
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null());
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use std::os::windows::process::CommandExt;
|
||||
const DETACHED_PROCESS: u32 = 0x0000_0008;
|
||||
const CREATE_NEW_PROCESS_GROUP: u32 = 0x0000_0200;
|
||||
command.creation_flags(DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP);
|
||||
}
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::process::CommandExt;
|
||||
command.process_group(0);
|
||||
}
|
||||
let mut child = command
|
||||
.spawn()
|
||||
let mut child = lutra_proc::spawn_detached(desktop, &[])
|
||||
.map_err(|e| format!("cannot start {}: {e}", desktop.display()))?;
|
||||
let deadline = Instant::now() + START_TIMEOUT;
|
||||
loop {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue