zsh-users
 help / color / mirror / code / Atom feed
From: Vincent Stemen <zsh@hightek.org>
To: zsh-users@sunsite.dk
Subject: Re: localtraps
Date: Mon, 25 Apr 2005 22:03:08 -0500	[thread overview]
Message-ID: <20050426030308.GA21501@quark.hightek.org> (raw)
In-Reply-To: <1050425163202.ZM25027@candle.brasslantern.com>

On Mon, Apr 25, 2005 at 04:32:02PM +0000, Bart Schaefer wrote:
> On Apr 25,  1:35am, Vincent Stemen wrote:
> } Subject: localtraps
> } 
> } I don't seem to be able to get the localtraps option to work.
> 
> Try it where the outer function is NOT a trap for the same signal
> that you're trapping inside the function.
> 
> I suspect that changing the trap of the same signal that is trapped
> is confusing the trap code, because low-level signal handling already
> requires that the signal handler restore itself before exiting, so in 
> effect you're restoring multiple different traps, and the order in
> which function exit and trap unwinding are processed is mixed up.

I have some new information.

I had hoped that I could get around the problem for now by explicitly
resetting the signal trap without using localtraps but, as you
indicated, it will not let me do anything with the same signal while
it is in the signal handler function.  This is a real problem that I
don't know how to get around.  Here is a new snippet of test code that
does basically what I am trying to do perfectly under the BSD shell.

#--------------------------------
#!/bin/sh

abort()
{
  echo 
  echo '** Aborting program **'
  echo 

  exit 1
}

signal()
{
  local signal=$1

  if [ -n "$script" ]
  then
      trap abort INT  
      echo -e "\n$0: $script Interrupted.  Hit ^C again to abort everything."
      sleep 2
      echo -n "Continuing "
      trap 'signal INT' INT  # Reset the signal trap for ^C
      return
  else
      abort
  fi
}


script=foo
trap 'signal' INT

echo -n "Doing something important "
for n in 1 2 3 4 5 6 7 8 9
do
    echo -n "."
    sleep 1
done

echo
echo "Exiting normally"
echo
#--------------------------------

Here is the output using the BSD /bin/sh:

# sigtest
Doing something important ..^C
sigtest: foo Interrupted.  Hit ^C again to abort everything.
Continuing ..^C
sigtest: foo Interrupted.  Hit ^C again to abort everything.
^C
** Aborting program **


After the first time I hit ^C, I waited more than 2 seconds.
The second time I hit ^C twice and it called abort() as I wanted.


Trying this under Z shell, I get

# sigtest
Doing something important ..^C
sigtest6: foo Interrupted.  Hit ^C again to abort everything.
^CContinuing
sigtest6: foo Interrupted.  Hit ^C again to abort everything.
^CContinuing
sigtest6: foo Interrupted.  Hit ^C again to abort everything.
Continuing .......
Exiting normally


Since it ignores the trap statement in signal() I have no way of
aborting.

I am using Z shell in all the scripts I am working on because it is
generally so vastly better that bourne shell, but this is a real
handycap.

Any ideas?


-- 
Vincent Stemen
Avoid the VeriSign/Network Solutions domain registration trap!
Read how Network Solutions (NSI) was involved in stealing our domain name.
http://www.InetAddresses.net


  parent reply	other threads:[~2005-04-26  3:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-25  6:35 localtraps Vincent Stemen
2005-04-25 16:32 ` localtraps Bart Schaefer
2005-04-26  0:50   ` localtraps Vincent Stemen
2005-04-26  3:03   ` Vincent Stemen [this message]
2005-04-26 18:34     ` localtraps Peter Stephenson
2005-04-26 22:12       ` localtraps Vincent Stemen
2005-04-27  5:59         ` localtraps Bart Schaefer
2005-04-28  1:00           ` localtraps Vincent Stemen
2005-04-28  8:20             ` localtraps Bart Schaefer
2005-04-27  5:36       ` localtraps Bart Schaefer

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=20050426030308.GA21501@quark.hightek.org \
    --to=zsh@hightek.org \
    --cc=zsh-users@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).