From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: SIGCHLD in vfork child context Date: Fri, 19 May 2017 00:16:51 -0700 Organization: UCLA Computer Science Department Message-ID: <6649321c-6750-cfc5-cc06-3ed0569ad843@cs.ucla.edu> References: <057b10e5-03a8-8ff0-63d4-57eeb310b36e@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------769EFC460DA34A4DA038A7BD" X-Trace: blaine.gmane.org 1495178224 13421 195.159.176.226 (19 May 2017 07:17:04 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 19 May 2017 07:17:04 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 Cc: YAMAMOTO Mitsuharu , emacs-devel@gnu.org To: Andreas Schwab Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 19 09:16:59 2017 Return-path: Envelope-to: ged-emacs-devel@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 1dBc9j-0003LT-Ah for ged-emacs-devel@m.gmane.org; Fri, 19 May 2017 09:16:59 +0200 Original-Received: from localhost ([::1]:56953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBc9o-0002oZ-OR for ged-emacs-devel@m.gmane.org; Fri, 19 May 2017 03:17:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBc9h-0002oE-RO for emacs-devel@gnu.org; Fri, 19 May 2017 03:16:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBc9e-00073L-Jp for emacs-devel@gnu.org; Fri, 19 May 2017 03:16:57 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:53662) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dBc9e-00073B-9w for emacs-devel@gnu.org; Fri, 19 May 2017 03:16:54 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 2AA201600AD; Fri, 19 May 2017 00:16:53 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id hojFjvn-JpbH; Fri, 19 May 2017 00:16:51 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id D5B521600B0; Fri, 19 May 2017 00:16:51 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id YB0Py126M2Em; Fri, 19 May 2017 00:16:51 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.153.188.248]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id B13F11600AD; Fri, 19 May 2017 00:16:51 -0700 (PDT) In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214981 Archived-At: This is a multi-part message in MIME format. --------------769EFC460DA34A4DA038A7BD Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Andreas Schwab wrote: >> Which tree should we be barking up instead? > Don't abort. Good suggestion, thanks. I installed the attached patch to try to bark up the right tree, or to chew up the tree bark, or whatever.... --------------769EFC460DA34A4DA038A7BD Content-Type: text/x-patch; name="0001-Attempt-to-work-around-macOS-vfork-bug.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Attempt-to-work-around-macOS-vfork-bug.patch" >From 7c951fd51832badb09055a8e177f8ec358cbbdcf Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 19 May 2017 00:11:48 -0700 Subject: [PATCH] Attempt to work around macOS vfork bug Problem reported by YAMAMOTO Mitsuharu in: http://lists.gnu.org/archive/html/emacs-devel/2017-05/msg00342.html This is related to the fix for Bug#26397. * src/callproc.c (call_process_cleanup, call_process) [!MSDOS]: Report internal error if wait_for_termination fails. * src/sysdep.c (get_child_status): Return -1 if waitpid is buggy, instead of aborting. (wait_for_termination): Return bool success value. All callers changed. --- src/callproc.c | 13 +++++++++---- src/sysdep.c | 25 ++++++++++++++----------- src/syswait.h | 2 +- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/callproc.c b/src/callproc.c index e967e45..7c85eed 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -202,10 +202,11 @@ call_process_cleanup (Lisp_Object buffer) message1 ("Waiting for process to die...(type C-g again to kill it instantly)"); /* This will quit on C-g. */ - wait_for_termination (synch_process_pid, 0, 1); - + bool wait_ok = wait_for_termination (synch_process_pid, NULL, true); synch_process_pid = 0; - message1 ("Waiting for process to die...done"); + message1 (wait_ok + ? "Waiting for process to die...done" + : "Waiting for process to die...internal error"); } #endif /* !MSDOS */ } @@ -866,9 +867,10 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, make_number (total_read)); } + bool wait_ok = true; #ifndef MSDOS /* Wait for it to terminate, unless it already has. */ - wait_for_termination (pid, &status, fd0 < 0); + wait_ok = wait_for_termination (pid, &status, fd0 < 0); #endif /* Don't kill any children that the subprocess may have left behind @@ -878,6 +880,9 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, SAFE_FREE (); unbind_to (count, Qnil); + if (!wait_ok) + return build_unibyte_string ("internal error"); + if (WIFSIGNALED (status)) { const char *signame; diff --git a/src/sysdep.c b/src/sysdep.c index ac6eed0..70f4a9d 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -368,8 +368,8 @@ init_baud_rate (int fd) Use waitpid-style OPTIONS when waiting. If INTERRUPTIBLE, this function is interruptible by a signal. - Return CHILD if successful, 0 if no status is available; - the latter is possible only when options & NOHANG. */ + Return CHILD if successful, 0 if no status is available, and a + negative value (setting errno) if waitpid is buggy. */ static pid_t get_child_status (pid_t child, int *status, int options, bool interruptible) { @@ -392,13 +392,14 @@ get_child_status (pid_t child, int *status, int options, bool interruptible) pid = waitpid (child, status, options); if (0 <= pid) break; - - /* Check that CHILD is a child process that has not been reaped, - and that STATUS and OPTIONS are valid. Otherwise abort, - as continuing after this internal error could cause Emacs to - become confused and kill innocent-victim processes. */ if (errno != EINTR) - emacs_abort (); + { + /* Most likely, waitpid is buggy and the operating system + lost track of the child somehow. Return -1 and let the + caller try to figure things out. Possibly the bug could + cause Emacs to kill the wrong process. Oh well. */ + return pid; + } } /* If successful and status is requested, tell wait_reading_process_output @@ -413,11 +414,13 @@ get_child_status (pid_t child, int *status, int options, bool interruptible) CHILD must be a child process that has not been reaped. If STATUS is non-null, store the waitpid-style exit status into *STATUS and tell wait_reading_process_output that it needs to look around. - If INTERRUPTIBLE, this function is interruptible by a signal. */ -void + If INTERRUPTIBLE, this function is interruptible by a signal. + Return true if successful, false (setting errno) if CHILD cannot be + waited for because waitpid is buggy. */ +bool wait_for_termination (pid_t child, int *status, bool interruptible) { - get_child_status (child, status, 0, interruptible); + return 0 <= get_child_status (child, status, 0, interruptible); } /* Report whether the subprocess with process id CHILD has changed status. diff --git a/src/syswait.h b/src/syswait.h index 846a975..055562a 100644 --- a/src/syswait.h +++ b/src/syswait.h @@ -56,7 +56,7 @@ along with GNU Emacs. If not, see . */ #endif /* Defined in sysdep.c. */ -extern void wait_for_termination (pid_t, int *, bool); +extern bool wait_for_termination (pid_t, int *, bool); extern pid_t child_status_changed (pid_t, int *, int); #endif /* EMACS_SYSWAIT_H */ -- 2.7.4 --------------769EFC460DA34A4DA038A7BD--