From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11592 invoked by alias); 11 Dec 2011 20:57:11 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30001 Received: (qmail 26856 invoked from network); 11 Dec 2011 20:57:09 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 74.125.82.41 is neither permitted nor denied by SPF record at ntlworld.com) X-ProxyUser-IP: 86.6.29.42 Date: Sun, 11 Dec 2011 20:56:58 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Bug in sh emulation Message-ID: <20111211205658.365243c7@pws-pc.ntlworld.com> In-Reply-To: <20111211202024.07c046df@pws-pc.ntlworld.com> References: <111209184747.ZM5000@torch.brasslantern.com> <20111210194022.5051f91c@pws-pc.ntlworld.com> <20111210232801.7dc8fef2@pws-pc.ntlworld.com> <20111211193949.2d58062b@pws-pc.ntlworld.com> <20111211202024.07c046df@pws-pc.ntlworld.com> X-Mailer: Claws Mail 3.7.9 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable (sorry! it's me again... however, this time I think I'm really getting there...) > On Sun, 11 Dec 2011 19:39:49 +0000 > Peter Stephenson wrote: > I'm vaguely coming to the conclusion the SIGTTOU's are endemic because > we only do the attachtty() from the new process, which starts off in the > background, and hence the signal ignoring is a key feature... http://www.gnu.org/s/hello/manual/libc/Job-Control-Signals.html =E2=80=94 Macro: int SIGTTOU This is similar to SIGTTIN, but is generated when a process in a background job attempts to write to the terminal *or set its modes*. ^^^^^^^^^^^^^^^^ Aha! I think the improbability sum is now complete. Why the bug occurred: - POSIXJOBS and MONITOR are on initially - Fork for subshell - attachtty() in subshell, which is in background to begin with --- parent shell is foreground. This works because SIGTTOU is being ignored. - Shell stopped ignoring SIGTTOU (wrong because...) - MONITOR left on because of POSIXJOBS (correct because this is a subshell) - Fork for pipeline - attachtty() again... SIGTTOU not being ignored, so this causes mayhem. What should happen: - Fork for subshell as before - attachtty() as before - Shell keeps ignoring SIGTTOU because... - MONITOR is left on for POSIXJOBs as this is a (...) subshell in the foreground. - Fork for pipeline - attachtty() works because SIGTTOU is still ignored - Now stop ignoring SIGTTOU because the pipeline element is not a (...) subshell, it's some random command - MONITOR is turned off for the same reason. So I think I've convinced myself the immediately preceding patch is correct. In addition to fixing the bug we get: % emulate sh -c '(echo foo | grep foo & jobs)'=20 [2] done echo foo |=20 running grep foo % foo (some inevitable races meaning it may not look quite like that) as job control in the subshell has stayed on because of POSIXJOBS and has worked correctly by entering the pipeline into the job table. --=20 Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/