From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.bugs Subject: bug#26397: [PATCH] Use vfork if possible on Darwin (bug#26397) Date: Mon, 10 Apr 2017 08:46:12 +0900 Organization: Faculty of Science, Chiba University Message-ID: References: <20170409191849.GA67152@breton.holly.idiocy.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: blaine.gmane.org 1491781637 1409 195.159.176.226 (9 Apr 2017 23:47:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 9 Apr 2017 23:47:17 +0000 (UTC) User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (=?UTF-8?Q?Shij=C5=8D?=) APEL/10.6 Emacs/22.3 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI) Cc: 26397@debbugs.gnu.org, Aaron Jensen To: Alan Third Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 10 01:47:09 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxMXy-0000Ek-M6 for geb-bug-gnu-emacs@m.gmane.org; Mon, 10 Apr 2017 01:47:06 +0200 Original-Received: from localhost ([::1]:59986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxMY4-00059g-CU for geb-bug-gnu-emacs@m.gmane.org; Sun, 09 Apr 2017 19:47:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxMXx-00059X-R2 for bug-gnu-emacs@gnu.org; Sun, 09 Apr 2017 19:47:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxMXu-00017l-Ni for bug-gnu-emacs@gnu.org; Sun, 09 Apr 2017 19:47:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42076) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxMXu-00017h-Jd for bug-gnu-emacs@gnu.org; Sun, 09 Apr 2017 19:47:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cxMXu-0003Hs-9V for bug-gnu-emacs@gnu.org; Sun, 09 Apr 2017 19:47:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: YAMAMOTO Mitsuharu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 09 Apr 2017 23:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26397 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 26397-submit@debbugs.gnu.org id=B26397.149178157812584 (code B ref 26397); Sun, 09 Apr 2017 23:47:02 +0000 Original-Received: (at 26397) by debbugs.gnu.org; 9 Apr 2017 23:46:18 +0000 Original-Received: from localhost ([127.0.0.1]:40275 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxMXC-0003Gs-Ic for submit@debbugs.gnu.org; Sun, 09 Apr 2017 19:46:18 -0400 Original-Received: from mathmail.math.s.chiba-u.ac.jp ([133.82.132.2]:61796) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxMX9-0003Gg-Q6 for 26397@debbugs.gnu.org; Sun, 09 Apr 2017 19:46:16 -0400 Original-Received: from fermat1.math.s.chiba-u.ac.jp (fermat [192.168.32.10]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id 67B92F08F4; Mon, 10 Apr 2017 08:46:12 +0900 (JST) (envelope-from mituharu@math.s.chiba-u.ac.jp) In-Reply-To: <20170409191849.GA67152@breton.holly.idiocy.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:131422 Archived-At: >>>>> On Sun, 9 Apr 2017 20:18:49 +0100, Alan Third said: > src/conf_post.h: Remove defines forcing use of fork. > src/process.c (create_process): Use fork if pty_flag is set, otherwise > vfork. With this patch, setsid in callproc.c gets called in a vfork child context. It results in EPERM on Darwin. According to ChangeLog, setsid in callproc.c seems to be used for disconnecting from the controlling terminal (so as to avoid using /dev/tty accidentally?). 1997-06-11 Paul Eggert * callproc.c (Fcall_process): Use setsid to disconnect child process from controlling terminal. If that is the case (i.e., if we don't have to make the child process a session leader), then we don't need setsid when the Emacs process doesn't have the controlling terminal, which is common for Mac-native GUI sessions. It doesn't apply for TTY or X11 sessions, but fork is not that slow there. YAMAMOTO Mitsuharu mituharu@math.s.chiba-u.ac.jp diff --git a/src/callproc.c b/src/callproc.c index 1e3d661eef..b3ffeb57af 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -591,6 +591,20 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, pid = child_setup (filefd, fd_output, fd_error, new_argv, 0, current_dir); #else /* not WINDOWSNT */ +#ifdef DARWIN_OS + /* Darwin doesn't let us run setsid after a vfork, so use fork when + necessary. */ + bool did_fork_p; + int ctfd = emacs_open ("/dev/tty", O_NOCTTY, 0); + + if (ctfd >= 0) + { + emacs_close (ctfd); + pid = fork (); + did_fork_p = true; + } + else +#endif /* vfork, and prevent local vars from being clobbered by the vfork. */ { Lisp_Object volatile buffer_volatile = buffer; @@ -609,6 +623,9 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, callproc_fd_volatile[i] = callproc_fd[i]; pid = vfork (); +#ifdef DARWIN_OS + did_fork_p = false; +#endif buffer = buffer_volatile; coding_systems = coding_systems_volatile; @@ -631,6 +648,9 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, { unblock_child_signal (&oldset); +#ifdef DARWIN_OS + if (did_fork_p) +#endif setsid (); /* Emacs ignores SIGPIPE, but the child should not. */