From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18656 invoked from network); 11 Jul 2009 18:57:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from new-brage.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.254.104) by ns1.primenet.com.au with SMTP; 11 Jul 2009 18:57:31 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 57335 invoked from network); 11 Jul 2009 18:57:24 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 Jul 2009 18:57:24 -0000 Received: (qmail 10102 invoked by alias); 11 Jul 2009 18:57:16 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 27131 Received: (qmail 10084 invoked from network); 11 Jul 2009 18:57:15 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 11 Jul 2009 18:57:15 -0000 Received: from mtaout02-winn.ispmail.ntl.com (mtaout02-winn.ispmail.ntl.com [81.103.221.48]) by bifrost.dotsrc.org (Postfix) with ESMTP id 482A280307FA for ; Sat, 11 Jul 2009 20:57:11 +0200 (CEST) Received: from aamtaout04-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20090711185711.VJRI6611.mtaout02-winn.ispmail.ntl.com@aamtaout04-winn.ispmail.ntl.com> for ; Sat, 11 Jul 2009 19:57:11 +0100 Received: from pws-pc ([81.107.42.185]) by aamtaout04-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20090711185711.EEKX22934.aamtaout04-winn.ispmail.ntl.com@pws-pc> for ; Sat, 11 Jul 2009 19:57:11 +0100 Date: Sat, 11 Jul 2009 19:57:02 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: non-interactive set -m Message-ID: <20090711195702.52896b2a@pws-pc> In-Reply-To: References: <200907080858.n688wXfc030608@news01.csr.com> <200907081349.n68DneSv001850@news01.csr.com> <20090709212345.05cc2213@pws-pc> X-Mailer: Claws Mail 3.7.1 (GTK+ 2.16.2; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Cloudmark-Analysis: v=1.0 c=1 a=9vXuR5GGAAAA:8 a=NLZqzBF-AAAA:8 a=1k4osxoEkbrBGAKfzp0A:9 a=LqZQXI5E5XjxKawrveEA:7 a=Zfj7ncPQbVApG5yi4Ve-LzNsdg0A:4 a=Mo27u2NpdeAA:10 a=eDFNAWYWrCwA:10 a=_dQi-Dcv4p4A:10 X-Virus-Scanned: ClamAV 0.94.2/9555/Sat Jul 11 10:31:19 2009 on bifrost X-Virus-Status: Clean On Fri, 10 Jul 2009 03:32:59 +0000 (UTC) Eric Blake wrote: > Eric Blake byu.net> writes: > > > $ Src/zsh -c '(set -m); echo $?' > > zsh:set:1: can't change option: -m > > $ zsh -ci '(set -m); echo $?' > zsh:set:1: can't change option: -m This is getting murkier. When we enter a subshell, we close the file descriptor pointing to the terminal. It's not clear to me this is strictly necessary: if we have a non-interactive shell, we will open that file descriptor if we can and keep it around permanently (that's why the initial patch to allow setting -m non-interatively was so simple), so obviously it's not strictly necessary to close it when a shell isn't interactive / doesn't have job control. What I think is necessary is getting rid of "shout", the FILE opened to the terminal, which is strictly for interactive use only and hence inappropriate in a subshell (we don't want the subshell trying to do line editing, etc.). So it's possible the following patch makes things work. (The other chunk is because we allow "jobs" to work in a subshell so you can pipe its output---if you "set -m" you're effectively making the shell the output for "jobs" twice.) Again, this passed a trivial smoke test. From the non-interactive case I think keeping SHTTY around is benign, but we're heading into more difficult territory. Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.168 diff -u -r1.168 exec.c --- Src/exec.c 11 Jul 2009 16:43:00 -0000 1.168 +++ Src/exec.c 11 Jul 2009 18:52:56 -0000 @@ -931,11 +931,7 @@ zsh_subshell++; if ((flags & ESUB_REVERTPGRP) && getpid() == mypgrp) release_pgrp(); - if (SHTTY != -1) { - shout = NULL; - zclose(SHTTY); - SHTTY = -1; - } + shout = NULL; if (isset(MONITOR)) { signal_default(SIGTTOU); signal_default(SIGTTIN); Index: Src/jobs.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v retrieving revision 1.69 diff -u -r1.69 jobs.c --- Src/jobs.c 10 Jul 2009 11:08:48 -0000 1.69 +++ Src/jobs.c 11 Jul 2009 18:52:56 -0000 @@ -1307,7 +1307,8 @@ if (monitor && oldmaxjob) { int sz = oldmaxjob * sizeof(struct job); - DPUTS(oldjobtab != NULL, "BUG: saving job table twice\n"); + if (oldjobtab) + free(oldjobtab); oldjobtab = (struct job *)zalloc(sz); memcpy(oldjobtab, jobtab, sz); -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/