Last active
April 20, 2017 15:26
-
-
Save aaronjensen/f45894ddf431ecbff78b1bcf533d3e6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 0ade1fe11600b0550db26e4be8d46784f1202075 Mon Sep 17 00:00:00 2001 | |
From: Alan Third <[email protected]> | |
Date: Sun, 9 Apr 2017 20:10:33 +0100 | |
Subject: [PATCH] Use vfork if possible on Darwin (bug#26397) | |
Co-authored-by: YAMAMOTO Mitsuharu <[email protected]> | |
* src/conf_post.h (HAVE_WORKING_VFORK): Don't undef. | |
(vfork): Don't define. | |
* src/process.c (create_process) [DARWIN_OS]: Use fork if pty_flag is | |
set, otherwise vfork. | |
* src/callproc.c (call_process) [DARWIN_OS]: Use TIOCNOTTY to detach | |
the controlling terminal instead of setsid. | |
--- | |
src/callproc.c | 12 ++++++++++++ | |
src/conf_post.h | 6 ------ | |
src/process.c | 9 +++++++++ | |
3 files changed, 21 insertions(+), 6 deletions(-) | |
diff --git a/src/callproc.c b/src/callproc.c | |
index a781e47b17..8058f45c9e 100644 | |
--- a/src/callproc.c | |
+++ b/src/callproc.c | |
@@ -52,6 +52,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |
#include "syswait.h" | |
#include "blockinput.h" | |
#include "frame.h" | |
+#include "systty.h" | |
#ifdef MSDOS | |
#include "msdos.h" | |
@@ -635,7 +636,18 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, | |
{ | |
unblock_child_signal (&oldset); | |
+#ifdef DARWIN_OS | |
+ /* Darwin doesn't let us run setsid after a vfork, so use | |
+ TIOCNOTTY when necessary. */ | |
+ int j = emacs_open ("/dev/tty", O_RDWR, 0); | |
+ if (j >= 0) | |
+ { | |
+ ioctl (j, TIOCNOTTY, 0); | |
+ emacs_close (j); | |
+ } | |
+#else | |
setsid (); | |
+#endif | |
/* Emacs ignores SIGPIPE, but the child should not. */ | |
signal (SIGPIPE, SIG_DFL); | |
diff --git a/src/conf_post.h b/src/conf_post.h | |
index 893b6b9c56..c7fde44a95 100644 | |
--- a/src/conf_post.h | |
+++ b/src/conf_post.h | |
@@ -94,12 +94,6 @@ typedef bool bool_bf; | |
#define realloc unexec_realloc | |
#define free unexec_free | |
#endif | |
-/* The following solves the problem that Emacs hangs when evaluating | |
- (make-comint "test0" "/nodir/nofile" nil "") when /nodir/nofile | |
- does not exist. Also, setsid is not allowed in the vfork child's | |
- context as of Darwin 9/Mac OS X 10.5. */ | |
-#undef HAVE_WORKING_VFORK | |
-#define vfork fork | |
#endif /* DARWIN_OS */ | |
/* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use | |
diff --git a/src/process.c b/src/process.c | |
index b35dd8fcc2..3fff2848e1 100644 | |
--- a/src/process.c | |
+++ b/src/process.c | |
@@ -1823,7 +1823,16 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir) | |
int volatile forkerr_volatile = forkerr; | |
struct Lisp_Process *p_volatile = p; | |
+#ifdef DARWIN_OS | |
+ /* Darwin doesn't let us run setsid after a vfork, so use fork when | |
+ necessary. */ | |
+ if (pty_flag) | |
+ pid = fork (); | |
+ else | |
+ pid = vfork (); | |
+#else | |
pid = vfork (); | |
+#endif | |
current_dir = current_dir_volatile; | |
lisp_pty_name = lisp_pty_name_volatile; | |
-- | |
2.12.2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment