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

Re: [BUG] exec + builtin and traps



On 2017-09-12 11:19:06 +0100, Peter Stephenson wrote:
> On Tue, 12 Sep 2017 12:02:57 +0200
> Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> > For zsh 5.4.1, the zshbuiltins(1) man page says:
> > 
> >     exec [ -cl ] [ -a argv0 ] [ command [ arg ... ] ]
> >            Replace the current shell with command rather than forking.
> >            If command is a shell builtin command or a shell  function,
> >            the shell executes it, then immediately exits.
> 
> It means immediately after the command has finished executing, not while
> it's executing.
> 
> > #!/usr/bin/env zsh
> > 
> > trap 'echo foo' USR1
> > 
> > echo $$
> > ( sleep 1; kill -USR1 $$ ) &
> > exec eval sleep 2
> 
> So in your case it's still exectuing the eval sleep 2.

No, by default (with TRAPS_ASYNC unset), traps are run *after* the
child process has exited:

    TRAPS_ASYNC
        While  waiting  for a program to exit, handle signals and run
        traps immediately.  Otherwise the trap is run after  a  child
        process  has  exited.  Note this does not affect the point at
        which traps are run for any case other than when the shell is
        waiting for a child process.

But if the shell immediately exits after the command has been
executed, this means that traps would not be run.

> I don't actually understand your interpretation --- given eval is a
> builtin and the eval is going to take 2 seconds because it dispatches to
> a sleep, how could the shell exit before that?

See above.

> diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
> index 3afe990..d6aa078 100644
> --- a/Doc/Zsh/builtins.yo
> +++ b/Doc/Zsh/builtins.yo
> @@ -669,7 +669,7 @@ an empty string or whitespace) the return status is zero.
>  item(tt(exec) [ tt(-cl) ] [ tt(-a) var(argv0) ] [ var(command) [ var(arg) ... ] ])(
>  Replace the current shell with var(command) rather than forking.
>  If var(command) is a shell builtin command or a shell function,
> -the shell executes it, then immediately exits.
> +the shell executes it, and exits when the command is complete.

This still does not describe the observed behavior when TRAPS_ASYNC
is unset.

-- 
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