From aac62ce5acd2ef4d05a54bc13b7cf30c30f129b2 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 11 Apr 2019 08:41:20 +0000 Subject: Fix macos subprocess execution This fixes the execution of subprocesses on macOS which could sometimes prevent actions like `SpawnNewProcess` or custom commands from launching their processes correctly. This fixes #2259. --- CHANGELOG.md | 1 + src/util.rs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4cb8793..7624faf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Reset scrolling region when the RIS escape sequence is received +- Subprocess spawning on macos ## Version 0.3.0 diff --git a/src/util.rs b/src/util.rs index b70f2f16..b8703012 100644 --- a/src/util.rs +++ b/src/util.rs @@ -13,7 +13,7 @@ // limitations under the License. use std::ffi::OsStr; -use std::process::Command; +use std::process::{Command, Stdio}; use std::{cmp, io}; #[cfg(not(windows))] @@ -22,8 +22,6 @@ use std::os::unix::process::CommandExt; #[cfg(windows)] use std::os::windows::process::CommandExt; #[cfg(windows)] -use std::process::Stdio; -#[cfg(windows)] use winapi::um::winbase::{CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW}; /// Threading utilities @@ -91,9 +89,20 @@ where { Command::new(program) .args(args) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) .before_exec(|| unsafe { - #[allow(deprecated)] - libc::daemon(1, 0); + match ::libc::fork() { + -1 => return Err(io::Error::last_os_error()), + 0 => (), + _ => ::libc::_exit(0), + } + + if ::libc::setsid() == -1 { + return Err(io::Error::last_os_error()); + } + Ok(()) }) .spawn()? -- cgit