From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6221 invoked from network); 11 Nov 2006 13:13:33 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.7 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 11 Nov 2006 13:13:33 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 62020 invoked from network); 11 Nov 2006 13:13:25 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 Nov 2006 13:13:25 -0000 Received: (qmail 13686 invoked by alias); 11 Nov 2006 13:13:21 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22997 Received: (qmail 13676 invoked from network); 11 Nov 2006 13:13:20 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 11 Nov 2006 13:13:20 -0000 Received: (qmail 61764 invoked from network); 11 Nov 2006 13:13:20 -0000 Received: from mtaout03-winn.ispmail.ntl.com (81.103.221.49) by a.mx.sunsite.dk with SMTP; 11 Nov 2006 13:13:17 -0000 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com with ESMTP id <20061111131322.NKVF1865.mtaout03-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com> for ; Sat, 11 Nov 2006 13:13:22 +0000 Received: from pwslaptop.csr.com ([81.107.40.110]) by aamtaout01-winn.ispmail.ntl.com with SMTP id <20061111131324.HXP644.aamtaout01-winn.ispmail.ntl.com@pwslaptop.csr.com> for ; Sat, 11 Nov 2006 13:13:24 +0000 Date: Sat, 11 Nov 2006 13:13:06 +0000 From: Peter Stephenson To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: PATCH: exit status Message-Id: <20061111131306.cd0bccd1.p.w.stephenson@ntlworld.com> In-Reply-To: <061110212844.ZM5583@torch.brasslantern.com> References: <200611100940.kAA9ewZY012583@news01.csr.com> <061110075808.ZM4615@torch.brasslantern.com> <200611101609.kAAG9ArT019938@news01.csr.com> <061110212844.ZM5583@torch.brasslantern.com> X-Mailer: Sylpheed version 2.2.9 (GTK+ 2.8.20; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 10 Nov 2006 21:28:44 -0800 Bart Schaefer wrote: > Aside: Here's an actual bug: > > zsh -fc 'trap "echo \$?" EXIT; echo ${example?oops}' > > The EXIT trap is not called when the shell exits on the error caused > by the ${var?message} construct. There are two bugs: we go straight to exit() instead of zexit(), and the EXIT trap doesn't get run if there has just been an error. Presumably it needs to be run unconditionally. (In fact, now I think about it, I'm a little bit suspicious that testing for "errflag" before running a trap, which is right down in the trap handling code, is ever the right thing to do.) There's another bug lurking: the exit might be within a forked subshell, so I've made it use _exit() in that case. > (Bash prints "127" in this case; > also, the exit status of zsh on that construct is 1 rather than 127, > but I don't know why bash chose 127.) The only mention I can see in the standard is for a command not found, which doesn't apply, but I presume status 127 is being used generally to signal an error in shell processing rather than a command return status. > On Nov 10, 4:09pm, Peter Stephenson wrote: > } > } I can see arguments for both sides; it turns whether you consider the > } "exit" command itself to have been executed before the exit traps run, > } which is a bit Zen-like. > > Think of it as a C program. If > > int question_mark = 0; > atexit() { printf("%d\n", question_mark); } > main() { question_mark = exit(3); } > > is a valid program and, when run, prints "3", then I'm on your side. > Otherwise I'm with Cragun. You certainly wouldn't expect exit() to return to main() after running, regardless of the point at which atexit() takes place, so I don't think this is parallel. All of which goes to show that there's no killer argument (that I've heard). Index: Src/builtin.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.169 diff -u -r1.169 builtin.c --- Src/builtin.c 10 Nov 2006 09:59:27 -0000 1.169 +++ Src/builtin.c 11 Nov 2006 13:05:12 -0000 @@ -4413,6 +4413,11 @@ * indicate we shouldn't do any recursive processing. */ in_exit = -1; + /* + * We want to do all remaining processing regardless of preceeding + * errors. + */ + errflag = 0; if (isset(MONITOR)) { /* send SIGHUP to any jobs left running */ Index: Src/subst.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/subst.c,v retrieving revision 1.67 diff -u -r1.67 subst.c --- Src/subst.c 7 Nov 2006 22:47:07 -0000 1.67 +++ Src/subst.c 11 Nov 2006 13:05:16 -0000 @@ -2591,8 +2591,17 @@ if (vunset) { *idend = '\0'; zerr("%s: %s", idbeg, *s ? s : "parameter not set"); - if (!interact) - exit(1); + if (!interact) { + if (mypid == getpid()) { + /* + * paranoia: don't check for jobs, but there shouldn't + * be any if not interactive. + */ + stopmsg = 1; + zexit(1, 0); + } else + _exit(1); + } return NULL; } break; -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/