unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Third <alan@idiocy.org>
To: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
Cc: 26397@debbugs.gnu.org, Alan Third <alan@idiocy.org>,
	Aaron Jensen <aaronjensen@gmail.com>
Subject: bug#26397: [PATCH v2] Use vfork if possible on Darwin (bug#26397)
Date: Mon, 10 Apr 2017 16:42:11 +0100	[thread overview]
Message-ID: <20170410154211.GA80342@breton.holly.idiocy.org> (raw)
In-Reply-To: <wlmvbpnk23.wl%mituharu@math.s.chiba-u.ac.jp>

* 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  | 13 +++++++++++++
 src/conf_post.h |  6 ------
 src/process.c   |  9 +++++++++
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/callproc.c b/src/callproc.c
index 05048576ce..792556c8e0 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -52,6 +52,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "syswait.h"
 #include "blockinput.h"
 #include "frame.h"
+#include "systty.h"
+#include "keyboard.h"
 
 #ifdef MSDOS
 #include "msdos.h"
@@ -626,7 +628,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 30c948e39a..95ebd5511c 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -99,12 +99,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 2f2e5c1b25..47a85f1c95 100644
--- a/src/process.c
+++ b/src/process.c
@@ -2049,7 +2049,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;
-- 

This patch includes everything so far.

I can’t say whether the TIOCNOTTY approach is correct either,
unfortunately.

Yamamoto‐san, I’m aware this is mostly your work, so if you’d prefer
I’m happy for you to commit it in your name.

-- 
Alan Third





  parent reply	other threads:[~2017-04-10 15:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-08  6:25 bug#26397: 25.1; call-process slow on macOS and slower on larger frames Aaron Jensen
2017-04-08  7:37 ` YAMAMOTO Mitsuharu
2017-04-08 15:47   ` Aaron Jensen
2017-04-08 19:19     ` Alan Third
2017-04-09 13:01       ` Alan Third
2017-04-09 15:07         ` Aaron Jensen
2017-04-09 19:18           ` bug#26397: [PATCH] Use vfork if possible on Darwin (bug#26397) Alan Third
2017-04-09 20:32             ` Andreas Schwab
2017-04-09 21:34               ` Alan Third
2017-04-09 23:46             ` YAMAMOTO Mitsuharu
2017-04-10  0:06               ` Aaron Jensen
2017-04-10  1:11                 ` YAMAMOTO Mitsuharu
2017-04-10  4:13                   ` Aaron Jensen
2017-04-10 15:42                   ` Alan Third [this message]
2017-04-11  7:06                     ` bug#26397: [PATCH v2] " YAMAMOTO Mitsuharu
2017-04-18  2:29                     ` Aaron Jensen
2017-04-18 10:48                       ` Alan Third

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170410154211.GA80342@breton.holly.idiocy.org \
    --to=alan@idiocy.org \
    --cc=26397@debbugs.gnu.org \
    --cc=aaronjensen@gmail.com \
    --cc=mituharu@math.s.chiba-u.ac.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).