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/platform/fallback.rs | 9 +++++++++ src/platform/mod.rs | 19 +++++++++++++++++++ src/platform/windows.rs | 6 ++++++ 3 files changed, 34 insertions(+) (limited to 'src/platform') diff --git a/src/platform/fallback.rs b/src/platform/fallback.rs index b27f181e..25bc761c 100644 --- a/src/platform/fallback.rs +++ b/src/platform/fallback.rs @@ -1,10 +1,19 @@ use std::path::PathBuf; +use std::process::Command; use super::{ClipboardImage, ForegroundJob, Signal}; /// Unsupported platform stub. pub fn raise_server_nofile_limit() {} +/// Unsupported platform stub. +pub fn detach_server_daemon_command(_command: &mut Command) {} + +/// Unsupported platform stub. +pub fn current_process_is_detached_server_daemon() -> bool { + false +} + /// Unsupported platform stub. pub fn foreground_job(_child_pid: u32) -> Option { None diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 0b5f9ecb..169b7c1c 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -40,6 +40,25 @@ pub(crate) const fn capabilities() -> PlatformCapabilities { } } +#[cfg(any(target_os = "linux", target_os = "macos"))] +pub fn detach_server_daemon_command(command: &mut std::process::Command) { + use std::os::unix::process::CommandExt; + + unsafe { + command.pre_exec(|| { + if libc::setsid() < 0 { + return Err(std::io::Error::last_os_error()); + } + Ok(()) + }); + } +} + +#[cfg(any(target_os = "linux", target_os = "macos"))] +pub fn current_process_is_detached_server_daemon() -> bool { + unsafe { libc::getsid(0) == libc::getpid() } +} + #[cfg(unix)] #[derive(Debug, Clone, PartialEq, Eq)] pub struct ClipboardCommand { diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 12a8345f..e7a77e35 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -46,6 +46,12 @@ struct WindowsProcessEntry { pub fn raise_server_nofile_limit() {} +pub fn detach_server_daemon_command(_command: &mut std::process::Command) {} + +pub fn current_process_is_detached_server_daemon() -> bool { + false +} + pub fn foreground_job(child_pid: u32) -> Option { let entries = snapshot_processes(); select_pane_foreground_job(child_pid, &entries) -- cgit v1.2.3