help / color / mirror / code / Atom feed
From: Greg Klanderman <gak@klanderman.net>
To: zsh-workers@zsh.org
Subject: Re: using trap function to cleanup and exit?
Date: Sun, 10 Apr 2022 12:30:08 -0400	[thread overview]
Message-ID: <87czho2967.fsf@lwm.klanderman.net> (raw)
In-Reply-To: <87fsmk2a03.fsf@lwm.klanderman.net> (Greg Klanderman's message of "Sun, 10 Apr 2022 12:12:12 -0400")

Is there an equivalent for exiting when using the trap builtin (list
traps)?  I don't completely understand the manual:

| a return from a list trap causes the surrounding context to return
| with the given status

I've tried both exit and return in a list trap, and am not seeing the
script exit.

Also, is exit intentionally disabled from within a trap function?
I didn't expect that, even with the special return handling.  So,
there is no way to exit 0 from a trap, since that is interpreted as
the signal having been handled, and wanting to continue executing?

With no traps of either type, should the child sleep remain after the
script is killed by a signal?

thank you,

>>>>> On April 10, 2022 Greg Klanderman <gak@klanderman.net> wrote:

> Hi Peter,
> I thought I'd changed that last night when I was reading that section
> of the manual, when I changed the exit value 1 to $(( 128 + $1 )), but
> apparently not.

> That does seem to be working better, in that the script itself does
> exit after running the cleanup, but the child sleep process still
> remains.

> I am playing with 'kill -9 -$$' in the trap function, but that seems
> like an awfully large hammer.

> thank you,
> Greg

>>>>> On April 10, 2022 Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:

>> On Sun, 2022-04-10 at 11:46 -0400, Greg Klanderman wrote:
>>> TRAPTERM () {
>>> echo "in TRAPTERM"
>>> cleanup TERM
>>> exit $(( 128 + $1 ))
>>> }

>> I haven't gone through this in great detail, so no guarantee this causes
>> everything to spring into life, but just to note that normal service
>> here would be obtained if you turn that "exit" into "return".  As
>> described in the Trap Functions in zshmisc, that's specially handled so
>> that the shell knows you want to continue to exit in a similar way to if
>> SIGTERM had been received without the trap function.

>> pws

  reply	other threads:[~2022-04-10 16:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-10 15:46 Greg Klanderman
2022-04-10 15:57 ` Peter Stephenson
2022-04-10 16:12   ` Greg Klanderman
2022-04-10 16:30     ` Greg Klanderman [this message]
2022-04-10 18:15       ` Lawrence Velázquez
2022-04-14  5:13         ` Greg Klanderman
2022-04-10 20:49       ` Bart Schaefer
2022-04-10 20:55         ` Bart Schaefer
2022-04-14  5:57         ` Greg Klanderman
2022-04-14 21:29           ` Bart Schaefer
2022-04-14 23:35             ` Bart Schaefer
2022-04-17 17:08               ` Daniel Shahaf
2022-04-15 22:27             ` Bart Schaefer
2022-04-19 18:42               ` Peter Stephenson
2022-04-19 18:55                 ` Peter Stephenson
2022-04-19 21:22                   ` Bart Schaefer
2022-04-20  8:16                     ` 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:

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

  git send-email \
    --in-reply-to=87czho2967.fsf@lwm.klanderman.net \
    --to=gak@klanderman.net \
    --cc=zsh-workers@zsh.org \


* 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


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