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#33050: 27.0.50; [macOS] Problem with process input with process-connection-type nil Date: Thu, 25 Oct 2018 20:10:06 +0300 Message-ID: References: <83a7n9udxv.fsf@gnu.org> <83ftwuq9ii.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1540490917 24371 195.159.176.226 (25 Oct 2018 18:08:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 25 Oct 2018 18:08:37 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (darwin) Cc: 33050@debbugs.gnu.org, fitzsim@fitzsim.org, alan@idiocy.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 25 20:08:33 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 1gFk3b-0006Ep-27 for geb-bug-gnu-emacs@m.gmane.org; Thu, 25 Oct 2018 20:08:31 +0200 Original-Received: from localhost ([::1]:56314 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFk5h-0006YZ-Hv for geb-bug-gnu-emacs@m.gmane.org; Thu, 25 Oct 2018 14:10:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFjL3-0006hw-45 for bug-gnu-emacs@gnu.org; Thu, 25 Oct 2018 13:22:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFj9y-0002B7-Or for bug-gnu-emacs@gnu.org; Thu, 25 Oct 2018 13:11:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38522) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gFj9y-0002Am-Fn for bug-gnu-emacs@gnu.org; Thu, 25 Oct 2018 13:11:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gFj9y-0001s3-4p for bug-gnu-emacs@gnu.org; Thu, 25 Oct 2018 13:11: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 17:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33050 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 33050-submit@debbugs.gnu.org id=B33050.15404874127126 (code B ref 33050); Thu, 25 Oct 2018 17:11:02 +0000 Original-Received: (at 33050) by debbugs.gnu.org; 25 Oct 2018 17:10:12 +0000 Original-Received: from localhost ([127.0.0.1]:42780 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gFj99-0001qr-Rf for submit@debbugs.gnu.org; Thu, 25 Oct 2018 13:10:12 -0400 Original-Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:40665) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gFj98-0001qk-FA for 33050@debbugs.gnu.org; Thu, 25 Oct 2018 13:10:10 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 694CAD92; Thu, 25 Oct 2018 13:10:09 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 25 Oct 2018 13:10:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= from:to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; s=fm1; bh=Ol6LErPqUH/7tj4VMxxwc7IK9T 6z7Cl4Vr4ydzEvyug=; b=VtJw/afC/CzLs7Qfpx9j97n545tS1ZWiJ/Z3TwFtWa Zi/1+wCS/Jkut8MepHaidAFkGqtPRg2PaTC/zjzdug5zU8P2yHK1OIbNMFFvsvIU Iu19aim2FhFvv7X+aGrktDg+V48OrD8iOKan80vEg7dQ6/kUJ53SLSZe7pyIPJ5i L7f4o6G59cl3sWOugpzKBmEI3nKUdR1ZZY7VLk4HsP9FcW6shfxyk0UXaWUXSBWx b7N3KEHgNWW4Dm05AQI/li5GMXIVEsMpwBTJi3nKgkqRfZ4EFSz5Z5Li/FKSfqBL jf8oS0SJNPu85NXswJmAsre7mUk0Zl7vSpzahIDGNnsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=Ol6LEr PqUH/7tj4VMxxwc7IK9T6z7Cl4Vr4ydzEvyug=; b=oPyzDkspJ9HX+uiQVjzX/0 ojz38X4lqUrIpxX8UFBebDyKaRhPjZOJZ6J7vjTpGsKKTuEQMLSlhhbr/XFgDGgb Nj++oOomelxW314yKhHe5VMJuLKoajddm/tsx3yIiVhExEEmd9sneCihldGiU2X0 /cG1LyRySFqn95CtK3N1ZOcIkB7p56IT2BTb+fRDew2mjorqckV3GEoxkWfeotDw IVJz15Qmgs1gQidzzP4P2Xb4aWCnKvMH41EyHOwvfwxRT5M9dejPGKrXLEpb6IF6 np8R+h/Ip3We39ywZaWQvcnrCBa/7qe9SMw68M9pEnmdrJG2WV4PmO3qG3tQwfxw == 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 50C30102E8; Thu, 25 Oct 2018 13:10:07 -0400 (EDT) In-Reply-To: <83ftwuq9ii.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 25 Oct 2018 19:24:53 +0300") 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:151609 Archived-At: On 25/10/2018 19:24 +0300, Eli Zaretskii wrote: >> From: Filipp Gunbin >> Cc: Eli Zaretskii , 33050@debbugs.gnu.org >> Date: Thu, 25 Oct 2018 18:51:17 +0300 >> >> With process-connection-type nil, we call vfork() and then setsid() >> apparently fails (at least to reset child's controlling terminal). >> >> I tried to change the above to just use fork(), and got the correct >> behavior. >> >> If only I knew how to fix this correctly, without reverting to fork() >> :-) Does anyone have ideas? I'll try to look into this further myself, >> and will write back. > > I'm probably missing something: why are you still trying to find a > solution, when one was already found? What's wrong with setting > process-connection-type non-nil in this case, at least for Darwin? Yes, setting p-c-t to t worked from the start, but it's just a workaround - there's still problem with p-c-t nil. I'm currently running with this patch, which is based on Alan's fix in callproc.c (call_process() had the same problem on Darwin). Filipp 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) {