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

Re: [BUG] exec + builtin and traps



On 2017-09-12 11:50:06 +0100, Peter Stephenson wrote:
> On Tue, 12 Sep 2017 12:39:19 +0200
> Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> > No, by default (with TRAPS_ASYNC unset), traps are run *after* the
> > child process has exited:
> 
> True, but the *builtin* is an eval list, that only terminates when it
> has executed an arbitrary set of other commands.  The trap is executed
> at the end of this list, before control returns back to eval.  We are
> not exec'ing sleep here, we are exec'ing eval, so there is time after
> the *child* process is executed, as in the TRAPS_ASYNC doc you quote.
> 
> eval, unlike exec, is not an permanent handoff of control to the
> following command.

OK, this was a bit confusing from the description of "eval" by POSIX,
which describes it as a way to construct a command:

  The eval utility shall construct a command by concatenating
  arguments together, separating each with a <space> character.
  The constructed command shall be read and executed by the shell.

BTW, the way zsh handles "eval" is still strange:

----------------------------------------
trap 'echo foo' USR1
( sleep 1; kill -USR1 $$; ) &
eval "wait && echo bar"
echo OK
----------------------------------------

outputs

foo
bar
OK

----------------------------------------
trap 'echo foo' USR1
( sleep 1; kill -USR1 $$; ) &
wait && echo bar
echo OK
----------------------------------------

outputs

foo
OK

All the other shells output

foo
OK

in both cases.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



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