From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25761 invoked by alias); 12 Sep 2017 10:39:23 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41681 Received: (qmail 11974 invoked by uid 1010); 12 Sep 2017 10:39:23 -0000 X-Qmail-Scanner-Diagnostics: from ioooi.vinc17.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(92.243.22.117):SA:0(-1.9/5.0):. Processed in 0.787896 secs); 12 Sep 2017 10:39:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: vincent@vinc17.net X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Date: Tue, 12 Sep 2017 12:39:19 +0200 From: Vincent Lefevre To: zsh-workers@zsh.org Subject: Re: [BUG] exec + builtin and traps Message-ID: <20170912103919.GA1794@zira.vinc17.org> Mail-Followup-To: zsh-workers@zsh.org References: <20170912100257.GA32535@zira.vinc17.org> <20170912111906.397cffec@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20170912111906.397cffec@pwslap01u.europe.root.pri> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/1.9.0-7151-vl-r99863 (2017-09-05) On 2017-09-12 11:19:06 +0100, Peter Stephenson wrote: > On Tue, 12 Sep 2017 12:02:57 +0200 > Vincent Lefevre 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 - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)