aboutsummaryrefslogtreecommitdiff
path: root/src/platform/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/mod.rs')
-rw-r--r--src/platform/mod.rs19
1 files changed, 19 insertions, 0 deletions
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 {