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

Re: Bug in recursive function calls, source and exit



On Fri, 2 Dec 2005 23:09:21 +0100
Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> In a French mailing-list, I've just heard of a bug related to
> recursive function calls, source and exit; I don't think it has
> been reported yet.

Thanks for passing it on.  You can see the bug more simply with:

echo exit >file
zsh -fc 'fn() { . ./file; echo Didn\'\''t exit; }; fn'

The problem is that we don't exit immediately from functions to allow
EXIT traps to run (zsh has more handling for these than other shells),
instead we force the function to return immediately.  However, the code
for "." was resetting the flag to return from the function.

Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.60
diff -u -r1.60 init.c
--- Src/init.c	15 Nov 2005 08:44:21 -0000	1.60
+++ Src/init.c	3 Dec 2005 00:03:30 -0000
@@ -1085,7 +1085,8 @@
     loops = oloops;                  /* the # of nested loops we are in      */
     dosetopt(SHINSTDIN, oldshst, 1); /* SHINSTDIN option                     */
     errflag = 0;
-    retflag = 0;
+    if (!exit_pending)
+	retflag = 0;
     scriptname = old_scriptname;
     free(cmdstack);
     cmdstack = ocs;

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page still at http://www.pwstephenson.fsnet.co.uk/



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