Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: test for trap EXIT fix.



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 <pws@xxxxxxx>                  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.
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author