aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2019-04-11 08:41:20 +0000
committerGitHub <noreply@github.com>2019-04-11 08:41:20 +0000
commitaac62ce5acd2ef4d05a54bc13b7cf30c30f129b2 (patch)
treea0d2403557343773dc72da81fb8a8d4f566a38d7
parent3478676f8f7ec6817b1e17d09926fc35a507977a (diff)
downloadalacritty-aac62ce5acd2ef4d05a54bc13b7cf30c30f129b2.tar.gz
alacritty-aac62ce5acd2ef4d05a54bc13b7cf30c30f129b2.zip
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.
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/util.rs19
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()?