From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#26397: [PATCH v2] Use vfork if possible on Darwin (bug#26397) Date: Mon, 10 Apr 2017 16:42:11 +0100 Message-ID: <20170410154211.GA80342@breton.holly.idiocy.org> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1491839004 12920 195.159.176.226 (10 Apr 2017 15:43:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 10 Apr 2017 15:43:24 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: 26397@debbugs.gnu.org, Alan Third , Aaron Jensen To: YAMAMOTO Mitsuharu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 10 17:43:17 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 1cxbTE-000325-Nz for geb-bug-gnu-emacs@m.gmane.org; Mon, 10 Apr 2017 17:43:12 +0200 Original-Received: from localhost ([::1]:35093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxbTI-0003U7-Ud for geb-bug-gnu-emacs@m.gmane.org; Mon, 10 Apr 2017 11:43:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxbT8-0003SM-HQ for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 11:43:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxbT4-0007ch-Ia for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 11:43:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43186) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cxbT4-0007cZ-EZ for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 11:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cxbT4-0003Ed-56 for bug-gnu-emacs@gnu.org; Mon, 10 Apr 2017 11:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 10 Apr 2017 15:43: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.149183894412387 (code B ref 26397); Mon, 10 Apr 2017 15:43:02 +0000 Original-Received: (at 26397) by debbugs.gnu.org; 10 Apr 2017 15:42:24 +0000 Original-Received: from localhost ([127.0.0.1]:41385 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxbSS-0003Dj-0l for submit@debbugs.gnu.org; Mon, 10 Apr 2017 11:42:24 -0400 Original-Received: from mail-wr0-f195.google.com ([209.85.128.195]:32834) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cxbSP-0003DT-EN for 26397@debbugs.gnu.org; Mon, 10 Apr 2017 11:42:22 -0400 Original-Received: by mail-wr0-f195.google.com with SMTP id l28so4858536wre.0 for <26397@debbugs.gnu.org>; Mon, 10 Apr 2017 08:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=/7JtFawtmGGZTu37c1aTpNGz+Wcf8hRjHcN6HTCajaI=; b=t5L4kEW9vqLtSqXdYSvfNZGPFNDxs4r/ICfQA35LcvZ/LvUDYDaW37ndqLrHgfComB Shl5NDAn5LBVA71roP9pAeZyPgvalP5ep9bdPlJGJUYLGAnX7pUicF8fNPPA9EDLYKE1 uMss3BmydWMMDh4TJH3S3m9JiK9/AF0xe9NtoAohhaM1TBlsyv21+KoqciQWolU44nwn NG4TAUQ3MhQNVdHtW34wtT0OqAu+fQAPvd0AqJ3X1sF4vHSYSI4ec4/mMS/NdLcx3Dwk 7A0+zovmj8IABgh/USwoGuof1UzPp3oBWc9dzYB+zKH0ug1X0yqY+txq4UDlZbaQwbV8 Df5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=/7JtFawtmGGZTu37c1aTpNGz+Wcf8hRjHcN6HTCajaI=; b=l2LQC8ZjO3GRPlMwHNTDMHWvJUY+4yeKakZCLT45Ys96FdwVhXrKv5oadX8fKRi07P yVlAkT6f1dISGctY7HrPLm4dDDbriUcirnuKZ0ayio6UKsJq90D9P3bvXwxxElMZJ+Cs SgzWoAn4/S+Oq/nS8WMYtLkwD1lrJ+lBgxDD2QCrOKhslMnFG8TUb7mroK4HQFBeygJP o4PMNpOcgnxnM1n8ut5L0ZEyYn04A56blUGTv+59g0VakgAyVRND9I44ya0QW274tsu1 dDE4eKAJBOBDM7E+me8H8zbRPcLk7TsGHGOQseoNdfPrOoZQ2DuwTuWajwv5knGhKHvI IyCA== X-Gm-Message-State: AN3rC/5TTfYXo6gyCTzoD6N3fFvVY0tjf8fQJLs4W0tBDWlSxSulnxzjhym8VXG8zk1ZNw== X-Received: by 10.223.171.65 with SMTP id r1mr5731151wrc.31.1491838935705; Mon, 10 Apr 2017 08:42:15 -0700 (PDT) Original-Received: from breton.holly.idiocy.org (ip6-2001-08b0-03f8-8129-6ca6-4e08-5c7a-e665.holly.idiocy.org. [2001:8b0:3f8:8129:6ca6:4e08:5c7a:e665]) by smtp.gmail.com with ESMTPSA id t85sm10726731wmt.23.2017.04.10.08.42.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Apr 2017 08:42:14 -0700 (PDT) Content-Disposition: inline In-Reply-To: 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:131447 Archived-At: * 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 . */ #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