commit aac62ce5acd2ef4d05a54bc13b7cf30c30f129b2
parent 3478676f8f7ec6817b1e17d09926fc35a507977a
Author: Christian Duerr <chrisduerr@users.noreply.github.com>
Date: Thu, 11 Apr 2019 08:41:20 +0000
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.
Diffstat:
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git 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
@@ -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()?