From 26db26e416318e17a6e7f3f196ec72109fb37998 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Tue, 30 Jun 2026 19:48:56 +0300 Subject: fix: keep remote sessions alive across disconnects --- src/server/autodetect.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/server/autodetect.rs') diff --git a/src/server/autodetect.rs b/src/server/autodetect.rs index f40be988..0c9e0cde 100644 --- a/src/server/autodetect.rs +++ b/src/server/autodetect.rs @@ -9,8 +9,6 @@ //! (escape hatch for users who want the traditional single-process behavior). use std::io; -#[cfg(unix)] -use std::os::unix::process::CommandExt; use std::path::Path; use std::path::PathBuf; use std::process::Command; @@ -218,12 +216,7 @@ fn build_server_daemon_command(exe: PathBuf) -> Command { .stdin(std::process::Stdio::null()) .stdout(std::process::Stdio::null()) .stderr(std::process::Stdio::null()); - #[cfg(unix)] - { - // Create a new process group so the server survives the parent's exit - // and doesn't receive SIGHUP when the client's terminal closes. - command.process_group(0); - } + crate::platform::detach_server_daemon_command(&mut command); match std::env::current_dir() { Ok(cwd) => { @@ -384,6 +377,24 @@ mod tests { })); } + #[cfg(target_os = "linux")] + #[test] + fn server_daemon_detach_creates_new_session() { + let mut command = Command::new("sh"); + command.arg("-c").arg( + r#"sid=$(ps -o sid= -p $$ | tr -d ' ') +test "$sid" = "$$" +"#, + ); + crate::platform::detach_server_daemon_command(&mut command); + + let status = command.status().unwrap(); + assert!( + status.success(), + "detached server child should be its own session leader" + ); + } + #[test] fn is_server_listening_returns_true_for_live_socket() { let dir = unique_test_dir("live"); -- cgit v1.2.3