unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#33154: 27.0.50; create_process on Darwin should not invoke setsid() after vfork() [PATCH]
@ 2018-10-25 19:30 Filipp Gunbin
  2018-10-26 11:12 ` Alan Third
  2018-11-05 17:28 ` Paul Eggert
  0 siblings, 2 replies; 16+ messages in thread
From: Filipp Gunbin @ 2018-10-25 19:30 UTC (permalink / raw)
  To: 33154

This resulted from analysis of bug 33050.  To avoid repetition, here's
the message with explanation:
http://lists.gnu.org/archive/html/bug-gnu-emacs/2018-10/msg00763.html

Suggested patch is below.

Thanks.

In GNU Emacs 27.0.50 (build 12, x86_64-apple-darwin17.7.0, NS appkit-1561.60 Version 10.13.6 (Build 17G65))
 of 2018-10-25 built on fgunbin.playteam.ru
Repository revision: f1f1687fcd8d48cd519c0f2977bcecbf394a7f01
System Description:  Mac OS X 10.13.6


diff --git a/src/process.c b/src/process.c
index 6cda4f27ac..1f8810927d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -2066,21 +2066,7 @@ 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.  Also, reset SIGCHLD handling after a vfork, as
-     apparently macOS can mistakenly deliver SIGCHLD to the child.  */
-  if (pty_flag)
-    pid = fork ();
-  else
-    {
-      pid = vfork ();
-      if (pid == 0)
-	signal (SIGCHLD, SIG_DFL);
-    }
-#else
   pid = vfork ();
-#endif
 
   current_dir = current_dir_volatile;
   lisp_pty_name = lisp_pty_name_volatile;
@@ -2091,15 +2077,35 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
   p = p_volatile;
 
   pty_flag = p->pty_flag;
-
   if (pid == 0)
 #endif /* not WINDOWSNT */
     {
+#ifdef DARWIN_OS
+      /* Work around a macOS bug, where SIGCHLD is apparently
+	 delivered to a vforked child instead of to its parent.  See:
+	 https://lists.gnu.org/r/emacs-devel/2017-05/msg00342.html
+      */
+      signal (SIGCHLD, SIG_DFL);
+#endif
+
       /* Make the pty be the controlling terminal of the process.  */
 #ifdef HAVE_PTYS
       /* First, disconnect its current controlling terminal.
 	 Do this even if !PTY_FLAG; see Bug#30762.  */
+#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
       /* Make the pty's terminal the controlling terminal.  */
       if (pty_flag && forkin >= 0)
 	{





^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2018-11-11 17:14 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-25 19:30 bug#33154: 27.0.50; create_process on Darwin should not invoke setsid() after vfork() [PATCH] Filipp Gunbin
2018-10-26 11:12 ` Alan Third
2018-11-07  1:35   ` Filipp Gunbin
2018-11-05 17:28 ` Paul Eggert
2018-11-06 13:46   ` Filipp Gunbin
2018-11-07  1:23   ` Filipp Gunbin
2018-11-07  7:41     ` Paul Eggert
2018-11-07  8:53       ` Filipp Gunbin
2018-11-07 15:40         ` Paul Eggert
2018-11-09  0:07       ` Alan Third
2018-11-09 10:29         ` Filipp Gunbin
2018-11-09 11:16           ` Andreas Schwab
2018-11-10 15:24             ` Filipp Gunbin
2018-11-10 17:09               ` Paul Eggert
2018-11-11 17:14                 ` Filipp Gunbin
2018-11-10 17:05         ` Paul Eggert

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).