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

Re: "{ } always { }" construct and return in called functions



On Mon, 18 May 2015 14:24:51 +0200
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> I would have expected the shell to exit when encountering the "exit"
> command, and run no further commands, no matter the circumstances.
> Probably a naive viewpoint considering all I've seen. I've reverted
> the patch locally for now, but I might investigate more later then.

bin_break(), which handles exit, says:

    case BIN_EXIT:
	if (locallevel > forklevel) {
	    /*
	     * We don't exit directly from functions to allow tidying
	     * up, in particular EXIT traps.  We still need to perform
	     * the usual interactive tests to see if we can exit at
	     * all, however.
	     *
	     * If we are forked, we exit the shell at the function depth
	     * at which we became a subshell, hence the comparison.
	     */
	    if (stopmsg || (zexit(0,2), !stopmsg)) {
		retflag = 1;
		breaks = loops;
		exit_pending = (num << 1) | 1;
		exit_level = locallevel;
	    }
	} else
	    zexit(num, 0);
	break;

"always" blocks are another form of tidy up that may or may not apply:
we're too deep here to know whether they do or not.

But there's nothing in the code in doshfunc() that should prevent the exit
happening there, unless there's some fork()ing going on that isn't
obvious.  We need to work out what path it's taking through both chunks
of code (some fprintf's might be good enough).

Hmmm...  I'm wondering if the fact you've started jobs is important.  It
shouldn't be, with the "&|", and the doshfunc() code is supposed
to make it irrelevant anyway by setting "stopmsg = 1".

pws



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