From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: grep-use-null-device Date: Thu, 01 Sep 2005 10:59:48 -0400 Message-ID: References: <87ll2kiczv.fsf@jurta.org> <878xyiyh2n.fsf-monnier+emacs@gnu.org> <87mzmy1wmh.fsf@jurta.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1125589713 12809 80.91.229.2 (1 Sep 2005 15:48:33 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 1 Sep 2005 15:48:33 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 01 17:48:25 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EArDf-0006WL-Bt for ged-emacs-devel@m.gmane.org; Thu, 01 Sep 2005 17:43:15 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EArHt-0007i1-Cr for ged-emacs-devel@m.gmane.org; Thu, 01 Sep 2005 11:47:37 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EArGr-0007PU-0C for emacs-devel@gnu.org; Thu, 01 Sep 2005 11:46:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EArGp-0007Ov-S2 for emacs-devel@gnu.org; Thu, 01 Sep 2005 11:46:32 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EArAI-0004jh-RR for emacs-devel@gnu.org; Thu, 01 Sep 2005 11:39:46 -0400 Original-Received: from [132.204.24.67] (helo=mercure.iro.umontreal.ca) by monty-python.gnu.org with esmtp (Exim 4.34) id 1EAqab-0004cD-Ia for emacs-devel@gnu.org; Thu, 01 Sep 2005 11:02:54 -0400 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id 0D4372CF52C; Thu, 1 Sep 2005 10:59:53 -0400 (EDT) Original-Received: from asado.iro.umontreal.ca (asado.iro.umontreal.ca [132.204.24.84]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id E678A4AC00A; Thu, 1 Sep 2005 10:59:48 -0400 (EDT) Original-Received: by asado.iro.umontreal.ca (Postfix, from userid 20848) id D0065504E; Thu, 1 Sep 2005 10:59:48 -0400 (EDT) Original-To: Juri Linkov In-Reply-To: <87mzmy1wmh.fsf@jurta.org> (Juri Linkov's message of "Wed, 31 Aug 2005 09:02:22 +0300") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-4.844, requis 5, autolearn=not spam, AWL 0.06, BAYES_00 -4.90) X-MailScanner-From: monnier@iro.umontreal.ca X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:42552 Archived-At: >>> `compilation-start' needs to check if the process is running >>> before calling `process-send-eof': >> >> That's odd. AFAICT no blobking operation takes place between the >> start-process and the process-send-eof, so the process-status should still >> be `run' no matter how quickly the process exits (because Emacs shouldn't >> process the SIGCHLD it receives until later). >> >> What am I missing? > The process exits during execution of create_process. The gdb log below > with a breakpoint on sigchld_handler demonstrates what really happens: > Breakpoint 4, sigchld_handler (signo=17) at process.c:6249 > 6249 XSETINT (p->raw_status_low, u.i & 0xffff); > (gdb) n > 6250 XSETINT (p->raw_status_high, u.i >> 16); > (gdb) n > 6253 if ((WIFSIGNALED (w) || WIFEXITED (w)) > (gdb) n > 6260 FD_CLR (XINT (p->infd), &input_wait_mask); > (gdb) n > 6261 FD_CLR (XINT (p->infd), &non_keyboard_wait_mask); > (gdb) p w > $1 = 512 <-- WIFEXITED > (gdb) bt > #0 sigchld_handler (signo=17) at process.c:6261 > #1 > #2 0x4031f784 in sigprocmask () from /lib/libc.so.6 > #3 0x0817af28 in create_process (process=141365940, new_argv=0xbfffe954, current_dir=140249731) at process.c:2153 > #4 0x0817a97d in Fstart_process (nargs=5, args=0xbfffea94) at process.c:1695 > ... > (gdb) fr 3 > #3 0x0817af28 in create_process (process=141365940, new_argv=0xbfffe954, current_dir=140249731) at process.c:2153 > 2153 sigprocmask (SIG_SETMASK, &procmask, 0); Oh, I now see that process-send-eof does: if (! NILP (XPROCESS (proc)->raw_status_low)) update_status (XPROCESS (proc)); which basically copies the asynchronously updated proc->raw_status_* to the synchronously updated proc->status. Since this process status can change asynchronously, adding your test for (eq (process-status proc) 'run) before calling process-send-eof doesn't fix the bug but just narrows the window of the race condition because the status can still change between the call to process-status and the call to process-send-eof. So I suggest the patch below instead, Stefan --- compile.el 01 sep 2005 10:04:39 -0400 1.379 +++ compile.el 01 sep 2005 10:58:22 -0400 @@ -1038,11 +1038,14 @@ outbuf command)))) ;; Make the buffer's mode line show process state. (setq mode-line-process '(":%s")) - (when compilation-disable-input - (process-send-eof proc)) (set-process-sentinel proc 'compilation-sentinel) (set-process-filter proc 'compilation-filter) (set-marker (process-mark proc) (point) outbuf) + (when compilation-disable-input + (condition-case nil + (process-send-eof proc) + ;; The process may have exited already. + (error nil))) (setq compilation-in-progress (cons proc compilation-in-progress))) ;; No asynchronous processes available.