From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15728 invoked from network); 2 Oct 2001 14:39:58 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 2 Oct 2001 14:39:58 -0000 Received: (qmail 8542 invoked by alias); 2 Oct 2001 14:39:50 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 15924 Received: (qmail 8526 invoked from network); 2 Oct 2001 14:39:48 -0000 To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: PATCH: test for trap EXIT fix. In-reply-to: "Bart Schaefer"'s message of "Tue, 02 Oct 2001 14:19:31 -0000." <1011002141931.ZM24534@candle.brasslantern.com> Date: Tue, 02 Oct 2001 15:39:10 +0100 Message-ID: <23405.1002033550@csr.com> From: Peter Stephenson Bart Schaefer wrote: > Can you explain to me why the subshell exits without ever leaving the > function scope? Why doesn't it just exit from a forked copy of the > function scope? There's special handling in the exec function hierarchy, starting with the `exiting' flag to execlist. The key chunk of code is this in execcmd(), around line 2365 of exec.c /* If we're forked (and we should be), no need to return */ DPUTS(last1 != 1 && !forked, "BUG: not exiting?"); execlist(state, 0, 1); ^ `exiting' flag That means we execute the list of command, and when we get to the end, exit the shell. I think this is correct --- I don't think we have any business leaving the function scope for a subshell contained entirely inside a function. At least, that's certainly true if you compare what happens when you drop off the end of a subshell list with what happens when you drop off the end of a current shell list. If you compare calling `exit' in the two, the behaviour is different, but that's not the typical case for a subshell list. We may be able to do some special tricks with `exiting' at the end of execlist(), making sure we don't exit too early from lower down in that case (because of the optimization for a final command to be exec'd if there's nothing left to do). Then we just execute any top level EXIT trap which has been left to us. -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. **********************************************************************