From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Filipp Gunbin Newsgroups: gmane.emacs.bugs Subject: bug#33154: 27.0.50; create_process on Darwin should not invoke setsid() after vfork() [PATCH] Date: Thu, 25 Oct 2018 22:30:12 +0300 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1540495753 25782 195.159.176.226 (25 Oct 2018 19:29:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 25 Oct 2018 19:29:13 +0000 (UTC) To: 33154@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 25 21:29:09 2018 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 1gFlJY-0006TV-JU for geb-bug-gnu-emacs@m.gmane.org; Thu, 25 Oct 2018 21:29:05 +0200 Original-Received: from localhost ([::1]:56651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFlLf-00036v-6Z for geb-bug-gnu-emacs@m.gmane.org; Thu, 25 Oct 2018 15:31:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFlLY-00036o-Cp for bug-gnu-emacs@gnu.org; Thu, 25 Oct 2018 15:31:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFlLS-00023p-O1 for bug-gnu-emacs@gnu.org; Thu, 25 Oct 2018 15:31:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38574) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gFlLS-00023l-Jd for bug-gnu-emacs@gnu.org; Thu, 25 Oct 2018 15:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gFlLS-0005U5-Cc for bug-gnu-emacs@gnu.org; Thu, 25 Oct 2018 15:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Filipp Gunbin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 25 Oct 2018 19:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 33154 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.154049585021062 (code B ref -1); Thu, 25 Oct 2018 19:31:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Oct 2018 19:30:50 +0000 Original-Received: from localhost ([127.0.0.1]:42832 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gFlLG-0005Te-Cv for submit@debbugs.gnu.org; Thu, 25 Oct 2018 15:30:50 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:46963) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gFlLF-0005TR-7x for submit@debbugs.gnu.org; Thu, 25 Oct 2018 15:30:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFlL5-0001ub-54 for submit@debbugs.gnu.org; Thu, 25 Oct 2018 15:30:44 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:33026) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFlL2-0001tR-8M for submit@debbugs.gnu.org; Thu, 25 Oct 2018 15:30:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFlL1-00033v-8y for bug-gnu-emacs@gnu.org; Thu, 25 Oct 2018 15:30:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFlKu-0001pp-EQ for bug-gnu-emacs@gnu.org; Thu, 25 Oct 2018 15:30:34 -0400 Original-Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:54483) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFlKj-0001iv-A9 for bug-gnu-emacs@gnu.org; Thu, 25 Oct 2018 15:30:19 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id AF5C13C5 for ; Thu, 25 Oct 2018 15:30:15 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 25 Oct 2018 15:30:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= from:to:subject:date:message-id:mime-version:content-type; s= fm1; bh=brwJnsGqjJ+XRzMuruEyCpehkA8feT+TSGRx9XmvTIo=; b=U0sE5elR khBGkLsRzZgVLNKilETLxG25RP4sulfA3+8014F50h6hImynCClRB7F9LXuHOgps gbgS0kCvLwT6C1kTBFKwc7wGjAZyWKy+Y6lbekN3CWXUXz4EqpA8xaLSo77VmiIF oOLvx6sCbm3wgou8Ra1ozChByAC8oMbzOjJcgoRUZ2IdH98seGTbV4Cw5I7P7qg8 AwOmjyck685xF4oXbkA+l2JaA9rPe63S2rKnL+cVcUmPlLeXoGUItqoGnJYAnEBj Irev4dHOt7O7fMlpm9J0yrkjrwo9PpnpzGGkwYyWLNrPcMrqa1IE1wf7KINmpc9q WKtb9bocRrwuUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=brwJnsGqjJ+XRzMuruEyCpehkA8fe T+TSGRx9XmvTIo=; b=EGHsP9cbmDkl4liJg3lsl1h1cDoVRRfdCLh9/TM8G9ZG8 tEteX/6E4u7beZgdZx4UBn0bacP+i29j6XHgrmiA5dWJ7dllpMTAWVIJiLeFVQbe vgV4QSuFzTPhqM8PUjGT9vg+dxpRbz5niIlwkYlkPgcpWDEMxV260+Q5ymM1dBJo Pn1+HR8nknFhlduQg33XXuNhJb35lXuko77o8wofoYgQhf6b6Zw7qzBBpk5CtLJb mMUqPxdveFzUW33IbLu2yGTdAbMF/zOxGil+BXr/SSIHXUqwtU2jATcdT7YRvxHC nxIewUsZA54WR6vF5bJVkd1XKpKfcfzA4mCLPl9iA== X-ME-Sender: X-ME-Proxy: Original-Received: from fgunbin.playteam.ru (unknown [95.161.147.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 93298102F2 for ; Thu, 25 Oct 2018 15:30:14 -0400 (EDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:151613 Archived-At: 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) {