zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: "Nelson H. F. Beebe" <beebe@math.utah.edu>,
	zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: zsh-4.1.1 and trap '...' DEBUG: a bug or a feature?
Date: Tue, 23 Mar 2004 18:49:17 +0000	[thread overview]
Message-ID: <232.1080067757@csr.com> (raw)
In-Reply-To: ""Nelson H. F. Beebe""'s message of "Tue, 23 Mar 2004 10:54:22 MST." <CMM.0.92.0.1080064462.beebe@psi.math.utah.edu>

"Nelson H. F. Beebe" wrote:
> We are finishing up a book on shell programming, 

Oh, you too.  (Actually, ours isn't really on programming, it's on
command-line usage.)

> 	% cat debug-trap
> 	trap 'echo This is an EXIT trap' EXIT
> 	trap 'echo This is a DEBUG trap' DEBUG
> 	pwd
> 	pwd
> 	pwd
> 	pwd
> 
> Next zsh-4.1.1 (the latest):
> 
> 	% zsh debug-trap
> 	This is a DEBUG trap
> 	/tmp
> 	This is a DEBUG trap
> 	/tmp
> 	This is a DEBUG trap
> 	/tmp
> 	This is a DEBUG trap
> 	/tmp
> 	This is a DEBUG trap
> 	This is an EXIT trap
> 	This is a DEBUG trap
> 
> Notice that zsh takes one final DEBUG trap that bash does not.
> 
> Is this a bug, or a feature?

Strictly, it's not a bug, as you saw from the docs.  The extra DEBUG is
running when the code in the EXIT trap is run.  There is (necessarily)
code to prevent recursive running of traps, but it does not extend to
different traps.

However, we can redocument our way out of it --- I would guess no one is
relying on this behaviour.  I don't think the current behaviour is
desirable.

I've noticed that we always queue signals when running traps.  This
implies ordinary traps (i.e not ZERR, DEBUG, EXIT) are never run inside
one another.  We could extend this to all traps, but it's not
necessarily convenient all the time.

The other obvious possibilities are not running other traps only inside
EXIT traps, or not running DEBUG traps inside other traps.  There are
also sorts of permutations.

I have't had time to look at how bash and ksh handle these possibilities.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


  parent reply	other threads:[~2004-03-23 18:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-23 17:54 Nelson H. F. Beebe
2004-03-23 18:20 ` Wayne Davison
2004-03-23 18:49 ` Peter Stephenson [this message]
2004-03-24 12:29   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=232.1080067757@csr.com \
    --to=pws@csr.com \
    --cc=beebe@math.utah.edu \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).